【问题标题】:ExtJS JsonStore not populatingExtJS JsonStore 未填充
【发布时间】:2011-04-21 23:38:54
【问题描述】:

我的 JsonStore 似乎没有填充。当我运行代码时,它会触发请求,该请求会返回 json。当我检查数据存储时,数据数组是空的。

我错过了什么?谢谢。

我定义了这个 JsonStore:

CCList.ListStore = new Ext.data.JsonStore({
    root: 'rows',
    idProperty: 'Id',
    fields: ['Id', 'Description'],
    autoLoad: true,
    proxy: new Ext.data.HttpProxy({
        method: 'GET',
        url: '/costcenters/getjson'
    }),
    listeners: {
        load: function (obj, records) {
            Ext.each(records, function (rec) {
                console.log(rec.get('Id'));
            });
        }
    }
});

试图将它绑定到这个 Ext.List

CCList.listPanel = new Ext.List({
            id: 'indexList',
            store: CCList.ListStore,
            itemTpl: '<div class="costcenter">{Id}-{Description}</div>'
            }
        });

我的网址返回这个 json:

{ "rows" : [ 
      { "Description" : "Jason",
        "Id" : "100"
      },
      { "Description" : "Andrew",
        "Id" : "200"
      }          
    ] }

【问题讨论】:

    标签: c# json extjs sencha-touch


    【解决方案1】:

    仅供参考,您不是在使用 ExtJS,而是在使用 Sencha Touch,它们是不同的,因此您在以后澄清这一点很重要。

    Ext.setup({
        onReady: function(){
            Ext.regModel('CostCenter', {
                idProperty: 'Id',
                fields: ['Id', 'Description']
            });
    
            var store = new Ext.data.Store({
                model: 'CostCenter',
                autoLoad: true,
                proxy: {
                    type: 'ajax',
                    method: 'GET',
                    url: 'data.json',
                    reader: {
                        type: 'json',
                        root: 'rows'
                    }
                },
                listeners: {
                    load: function(obj, records){
                        Ext.each(records, function(rec){
                            console.log(rec.get('Id'));
                        });
                    }
                }
            });
    
            new Ext.List({
                fullscreen: true,
                store: store,
                itemTpl: '<div class="costcenter">{Id}-{Description}</div>'
            });
    
        }
    });
    

    【讨论】:

    • 非常感谢。那么 JsonStore 对 Sencha Touch 无效吗?
    • 它在那里,但数据包的工作方式现在有点让它多余,你最好坚持我上面概述的方法。
    猜你喜欢
    • 1970-01-01
    • 2011-06-20
    • 1970-01-01
    • 1970-01-01
    • 2011-10-17
    • 2012-11-03
    • 1970-01-01
    • 1970-01-01
    • 2016-11-24
    相关资源
    最近更新 更多