【问题标题】:ExtJs Grid Auto Refresh using REST Proxy使用 REST 代理的 ExtJs 网格自动刷新
【发布时间】:2017-03-07 18:39:18
【问题描述】:

我尝试使用 REST 代理每 5 或 10 秒刷新一次网格,但网格不会多次刷新。请找到我们尝试过的代码。

Ext.define('App.Store.DeviceStore', {
extend: 'Ext.data.Store',
requires: [
    'Ext.data.proxy.Ajax',
    'Ext.data.reader.Json'
],
constructor: function(cfg) {
    var me = this;
    cfg = cfg || {};
    me.callParent([Ext.apply({
        storeId: 'app.store.DeviceStore',
        model: 'App.model.DeviceModel',
        activeRefreshTask:false,
        pageSize: 5,
        autoLoad: {
            pageSize: 5
        }
    }, cfg)]);
},listeners:{
    'load':function(store,records,successful,operation){
        if(successful === true && store.activeRefreshTask === false){
        var task = {
                identifyId: 'deviceListStore',
                run: function() {
                    if (App.app._currentPage == 'devicesform') {
                        store.reload();
                    } else {    
                        Ext.TaskManager.stop(this);
                    }
                },
                interval: '10000'
            }
            Ext.TaskManager.start(task);
            store.activeRefreshTask = true;
        }
    }
}

});

以上店铺的型号是

Ext.define('App.model.DeviceModel', {
extend: 'Ext.data.Model',
requires: [
    'Ext.data.field.String'
],
proxy:{
        type:'rest',
        reader: {
            type: 'json',
            rootProperty: 'data',
            totalProperty:'total'
        },
        useDefaultXhrHeader: false,
        headers:{'Content-Type':'application/json'},
        api: {
            read: 'url given gere'
        }
},

fields: [
    {
        type: 'string',
        name: 'id'
    },
    {
        type: 'string',
        name: 'name'
    },
    {
        type: 'string',
        name: 'desc'
    }, 
    {
        type: 'string',
        name: 'ipAddr'
    }

]

});

【问题讨论】:

  • 尝试使用存储加载而不是存储重新加载
  • @Mr.Bruno 也试过了,但这里的问题是任务没有多次运行
  • 我编辑了我的答案

标签: extjs grid


【解决方案1】:

我找到了问题,您已将间隔作为字符串传递给 lo 号码。 只需更改为interval: '10000' to inteval: 10000,您的任务运行程序就会运行良好。

【讨论】:

    【解决方案2】:
    var runner = new Ext.util.TaskRunner(),
        updateStore , task;
    
    updateStore = function() {
                            if (App.app._currentPage == 'devicesform') {
                                store.load();
                            } else {    
                                Ext.TaskManager.stop(this);
                            }
                        };
    
    task = runner.start({
        run: updateStore ,
        interval: 1000
    });
    

    可能您的store.reload 再次发送请求中的相同参数,所以对于不改变的请求没有任何改变。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-03-28
      • 2015-07-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多