开发者

ExtJS JsonStore not populating

My JsonStore does not seem to be populating. When I run the code, it fires off the request, which does return the json. When I inspect the data store, the data array is empty.

What I am missing? Thanks.

I have this JsonStore defined:

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) {
            Ex开发者_StackOverflow中文版t.each(records, function (rec) {
                console.log(rec.get('Id'));
            });
        }
    }
});

Trying to bind it to this Ext.List

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

My url returns this json:

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


FYI you're not using ExtJS, you're using Sencha Touch, they are different so it's important that you clarify in future.

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>'
        });

    }
});
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜