jb1*_*785 3 sencha-touch sencha-touch-2
我有一个设置了卡片布局的Sencha Touch 2.0应用程序.它包含一个仪表板,其中包含用户可以单击的图标和一个客户列表(xtype:'list').当应用程序加载时,我加载应用程序中的所有"卡",包括客户列表,但我不加载数据(通过代理),除非设置了localStorage变量.加载完所有内容后,我会通过检查localStorage变量来检查用户是否应该自动登录.如果他们自动登录,那么我的应用程序可以正常运行 如果他们不是我给他们显示"登录"卡,这基本上是一个登录表格.一旦他们提交此登录表单,我就会执行ajax调用.如果这回来正确,我将它们发送到"仪表板"卡.但在此之前,我正试图通过ajax调用加载客户列表:
var tmpId = { id: example.id };
var cListStore = Ext.create('example.store.CustomerList');
cListStore.getProxy().setExtraParams(tmpid);
cListStore.load();
Run Code Online (Sandbox Code Playgroud)
使用上面的代码,我可以看到我的代理调用正在发生,我可以看到响应是正确的.但是,当我看到仪表板,然后单击"客户"图标时,我看到一个空列表.我的工具栏就在那里,甚至我列表上的indexBar就在那里,只是没有数据.我不确定我在这里做错了什么.我在下面列出了我的列表视图,商店和模型,希望这将有助于任何看过这个的人:
Ext.define('example.view.CustomerList', {
extend: 'Ext.Container',
id: 'customerListContainer',
xtype: 'customerlist',
config: {
layout: 'fit',
items: [{
xtype: 'toolbar',
docked: 'top',
title: 'Customers',
items: [{
xtype: 'button',
text: 'Home',
id: 'customerListHomeButton',
ui: 'back'
}]
}, {
xtype: 'list',
itemTpl: '<div class="contact">{first_name} <strong>{last_name}</strong> </div>',
store: 'CustomerList',
id: 'customer_list',
grouped: true,
indexBar: true
}]
}
});
Ext.define('example.store.CustomerList', {
extend: 'Ext.data.Store',
id: 'customerListStore',
requires: ['example.model.CustomerList'],
config: {
model: 'example.model.CustomerList',
sorters: 'last_name',
/*
* This actually makes the ajax request
*/
proxy: {
type: 'ajax',
url: '/example/api/customerList.php',
extraParams: {
id: example.id
},
reader: {
type: 'json'
}
},
autoLoad: ((example.id > 0) ? true : false), //only fetch the data if we have a id, or else we'll get an error from our api
/*
* Set the group headers to the first letter of the last name
*/
grouper: {
groupFn: function (record) {
return record.get('last_name')[0];
}
}
}
});
Ext.define('example.model.CustomerList', {
extend: 'Ext.data.Model',
config: {
/*
* Define the fields we get back from our ajax request
*/
fields: [
'first_name',
'last_name',
'address1',
'address2',
'city',
'state',
'zip_code',
'phone_daytime',
'phone_evening',
'phone_cell',
'email']
}
});
Run Code Online (Sandbox Code Playgroud)
我还尝试将storeId放在Customer List存储中,然后使用以下代码而不是调用Ext.create():
Ext.StoreManager.get('storeid').load()
Run Code Online (Sandbox Code Playgroud)
这产生了相同的结果.我可以看到代理正确地获取数据但它仍然在我的列表组件中呈现.
我想通了,我删除了这些行:
var cListStore = Ext.create('example.store.CustomerList');
cListStore.getProxy().setExtraParams(tmpid);
cListStore.load();
Run Code Online (Sandbox Code Playgroud)
我在其位置添加了以下内容:
Ext.getStore('CustomerList').getProxy().setExtraParams(tmpid);
Ext.getStore('CustomerList').load();
Run Code Online (Sandbox Code Playgroud)
基本上我不需要创建我的商店的新实例,一个已经创建,所以我只需要一种方法来识别它(Ext.getStore),然后加载它.感谢所有关注它的人.
| 归档时间: |
|
| 查看次数: |
14602 次 |
| 最近记录: |