【发布时间】:2014-08-02 06:32:41
【问题描述】:
我有一个 Ext.List 显示某个帐户的帐户历史记录,对于每个帐户我加载自己的历史记录记录,例如,从以下网址:www.mysite.com/accounts/loadHistory?=accountId(或通过 POST 请求,没关系)。
在进入视图时为每个帐户重新加载数据的最佳做法是什么?
我现在的做法是这样的:
当进入视图时:
var store = Ext.getStore(storeId);
store.removeAll(); // 删除数据,这样在重新加载新帐户的数据之前不会显示旧帐户的历史记录
store.setParams(id).load(); //加载账户数据
查看:
Ext.define('myApp.view.AccountHistory', {
extend: 'Ext.List',
xtype: 'accounthistory',
config: {
store: 'accountHistoryStore',
emptyText: 'No history available',
itemCls: 'expandedListItem',
itemTpl: Ext.create('Ext.XTemplate',
'<p>{accountId} - {accountText}</p>')
},
initialize: function() {
this.callParent(arguments);
var accountData = this.config.accountData; // parameter passed to view
var store = Ext.getStore('accountHistoryStore');
store.removeAll(); // remove current store records so the old account's info is not shown till the new account is loaded
store.setParams(accountData.id); // set new proxy url
store.load(); // reload history for new account
}
});
商店:
Ext.define('eMaliApp.store.ChildActivities', {
extend: 'Ext.data.Store',
requires: [
'myApp.model.AccountHistory'
],
config: {
model: 'myApp.model.AccountHistory',
storeId: 'accountHistoryStore',
proxy: {
type: 'ajax',
url: myApp.utils.Config.getBaseUrl() + 'account/history',
method: 'post'
reader: {
type: 'json',
rootProperty: 'history'
}
}
}
});
【问题讨论】:
标签: extjs sencha-touch sencha-touch-2 sencha-touch-2.1