javascript - extjs 4 动态存储

标签 javascript extjs load store

我必须更新一些从商店获取数据的标签。我必须将新数据加载到商店中。每 10 秒一次。 这很简单 - 使用 setInternal() (因为 TaskRunner 不起作用 o_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 方法配置重新加载计时器 - 这不利于理解

关于javascript - extjs 4 动态存储,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15893267/

相关文章:

javascript - 如何在 ajax 请求中禁用/启用表单提交

javascript - 如何在 extjs 中正确设置按钮的图标大小?

image - 将位图从资源文件加载到图像

java - 图标图像加载速度不够快

javascript - Comet 连接超时

javascript - 使用 html 绑定(bind)显示 ko.observable

javascript - 覆盖 javascript/jquery 中的 CMD+N 或 CTRL+N 快捷键?

javascript - ExtJs 4 - Window.show() - 窗口尺寸非常小

javascript - 将消息集中在 Extjs 的属性文件中

javascript - 在 JavaScript 中加载页面