首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >未填充ExtJS JsonStore

未填充ExtJS JsonStore
EN

Stack Overflow用户
提问于 2011-04-22 07:38:54
回答 1查看 1K关注 0票数 2

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

我错过了什么?谢谢。

我定义了这个JsonStore:

代码语言:javascript
复制
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

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

我的url返回这个json:

代码语言:javascript
复制
{ "rows" : [ 
      { "Description" : "Jason",
        "Id" : "100"
      },
      { "Description" : "Andrew",
        "Id" : "200"
      }          
    ] }
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2011-04-22 08:07:26

仅供参考,你使用的不是ExtJS,而是Sencha Touch,它们是不同的,所以在未来澄清这一点很重要。

代码语言:javascript
复制
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>'
        });

    }
});
票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/5750928

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档