1
我必须更新一些从商店获取数据的标签。我必须在商店中加载新的数据。每10秒。 这很容易 - 使用setInternal()
(因为TaskRunner不工作o_0)_并调用store.load事件。 但我的任务更具体。 我也有一个包含两列的网格,并从商店获取一些数据,并且一些数据是自定义的。 这意味着在具有明确存储数据索引的列之前,在具有自定义字符串数据和一些数字数据的商店中有一些新记录... 可能很难用单词解释,但在代码中它看起来如此:extjs 4动态商店
//---Store---
Ext.define('App.store.Data', {
extend: 'Ext.data.Store',
autoLoad: false,
storeId:'Data',
model: 'App.model.DataModel',
proxy : {
type : 'ajax',
url: 'http://mybackend',
reader: {
type: 'json'
}
},
data:[first = true],
listeners:{
load: function()
{
if(first){
first=false;
myApp.getController('App.controller.Controller').StoreLoadHandler();
setInterval(function(){myApp.getController('App.controller.Controller').StoreLoadHandler();},10000);
}
}
}
});
//---Controller---
StoreLoadHandler: function(){
var store = this.getStore('Data');
//upload data from base into store
store.reload();
store.add(
[
{
fio: 'somedata',
//calculate some data and write it into store. All dataindexes are existsin model
operCount: parseInt(this.getStore('Data').first().get('isQuick')),
opersvod: (this.getStore('Data').first().get('opersvod')),
isQuick:parseInt(this.getStore('Data').first().get('isQuick')),
ipk: (this.getStore('Data').first().get('ipk')),
allCount: (this.getStore('Data').first().get('allCount')),
id: 0
},
{
fio:
...
id: 1
},
{
fio:
...
id: 2
}
]
);
//takes my labels and use setText, works brilliant
Ext.ComponentQuery.query('#TopPanel')[0].items.getAt(0).items.get('inW').setText(this.StoreCalc('iw'));
Ext.ComponentQuery.query('#TopPanel')[0].items.getAt(1).items.get('isClose').setText(this.StoreCalc('isClose'));
Ext.ComponentQuery.query('#TopPanel')[0].items.getAt(2).items.get('denied').setText(this.StoreCalc('denied'));
Ext.ComponentQuery.query('#BottomPanel')[0].items.getAt(0).items.get('allCount').setText(store.getAt(3).get('allCount'));
//use sort
store.sort([
{
property : 'id',
direction: 'ASC'
},
{
property : 'fio',
direction: 'ASK'//'DESC'
}
]);
store.destroy();
}
在这种情况下,当我拨打store.load()
方法或store.reload()
时,我在店中的自定义记录丢失。 如果我从列表中删除这个操作,我的自定义数据是保存并呈现在具有2列的网格中(数据索引是 - 'fio'和'operCount')... 问题在哪里?
谢谢!我已经知道问题出在哪里,但我的决定并不那么优雅...... 我把reload()所有的代码都放进去了。但现在有了你的帮助,我可以更好地解决我的问题! – Iexpmhihx 2013-04-09 13:03:42