我有一個自定義的數據存儲,存儲信息是否存儲已被加載一次或沒有。ExtJS存儲負載監聽器沒有被調用
/**
* Custom DataStore which stores the information whether data has been loaded once or not.
*/
Ext.example.Store = Ext.extend(Ext.data.Store, {
loaded: false,
initComponent: function() {
this.superclass().initComponent.call(this);
this.addEvents('load','beforeload');
},
isLoaded : function() {
return this.loaded;
},
listeners: {
'load' : function(store,records,options) {
this.loaded = true;
}
}
});
這工作正常,直到最近我添加一個'beforeload'事件監聽器到這個商店的一個實例。 'load'偵聽器現在不會被調用。
var accountsDataStore = new Ext.example.Store({
id : 'account',
proxy : new Ext.data.HttpProxy({
url : 'app/account/fetch/all',
method : 'post',
api : {
destroy : 'app/account/delete'
}
}),
reader : accountReader,
writer : accountWriter,
remoteSort : true,
sortInfo : {
field : 'createdOn',
direction : "DESC"
},
listeners: {
beforeload: function(store, options) {
var sort = options.params.sort;
// setting the sort parameters to match the property names in the DTO
switch(sort) {
case 'company' :
options.params.sort = 'company.name';
break;
default:
// do nothing
}
}
}
});
我在這裏做錯了什麼?也請讓我知道你的建議,以改善
你在哪裏加載店嗎?我看不到任何autoLoad:true或accountsDataStore.load()選項。 – Swar 2011-05-03 07:38:29
我嘗試在點擊標籤上加載商店。我的意圖是,如果商店先前已加載,則不加載商店 - 如果(!accountsDataStore.isLoaded()){ accountsDataStore.load(); }'。 'isLoaded'總是返回false,因爲永遠不會調用加載監聽器。 – Joji 2011-05-03 07:58:54
嗨,我面臨同樣的問題。你能告訴我你是如何解決這個問題的? – Shekhar 2012-02-10 05:35:32