Javascript ExtJS4动态存储
我必须更新一些从存储中获取数据的标签。我必须每10秒将新数据加载到存储中。 它很容易使用Javascript ExtJS4动态存储,javascript,extjs,load,store,Javascript,Extjs,Load,Store,我必须更新一些从存储中获取数据的标签。我必须每10秒将新数据加载到存储中。 它很容易使用setInternal()(因为TaskRunner无法运行到0)并调用store.load事件。 但我的任务要具体得多。 我还有一个包含两列的网格,从存储中获取一些数据,一些数据是自定义的。 这意味着,在具有明确存储数据索引的列之前,存储中有一些具有自定义字符串数据和一些数字数据的新记录。。。 这可能很难用文字来解释,但在代码中看起来是这样的: //---Store--- Ext.define('App.s
setInternal()
(因为TaskRunner无法运行到0)并调用store.load事件。
但我的任务要具体得多。
我还有一个包含两列的网格,从存储中获取一些数据,一些数据是自定义的。
这意味着,在具有明确存储数据索引的列之前,存储中有一些具有自定义字符串数据和一些数字数据的新记录。。。
这可能很难用文字来解释,但在代码中看起来是这样的:
//---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')。。。
问题在哪里 看起来您在调用
add
方法时存储区中没有数据。使用reload
方法的回调选项:
store.reload({callback: function() {
store.add(...);
}
})
注意:不要从
load
方法配置重新加载计时器-这不利于理解看起来您在调用add
方法时没有存储数据。使用reload
方法的回调选项:
store.reload({callback: function() {
store.add(...);
}
})
注意:不要从
load
方法配置重新加载计时器-这不利于理解谢谢!我已经知道问题出在哪里了,但我的决定并不那么优雅。。。我将所有其他代码放入reload()中。但是现在有了你的帮助,我可以更好地解决我的问题了!非常感谢。我已经知道问题出在哪里了,但我的决定并不那么优雅。。。我将所有其他代码放入reload()中。但是现在有了你的帮助,我可以更好地解决我的问题了!