【问题标题】:Loading data into JsonStore将数据加载到 JsonStore
【发布时间】:2011-04-29 21:20:16
【问题描述】:

我正在尝试将一些简单的数据放入 JsonStore,但它似乎不起作用。代码与示例几乎相同:

var itemListStore = new Ext.data.JsonStore({
   url: '/items/list',
   root: 'items',
   fields: [
      {name: 'id', type: 'string'},
      {name: 'name', type: 'string'},
   ]
});
itemListStore.load(); 
...
      items: [
      {
         xtype: 'listview',
         store: itemListStore,
         columnResize: false,
         flex: 1,
         columns: [
            {header: 'ID', dataIndex: 'id'},
            {header: 'Name', dataIndex: 'name'},
         ]
      }
...

不幸的是,这不起作用。表加载时没有行,存储中的计数为 68(由服务器返回,通过 listview.getStore().getCount() 获得)。如果我用 ArrayStore 和一些静态数据替换 JsonStore,我可以看到它们。

/items/list 的结果是:

{"items":
    [{"id": "a", "name": "Some name"},
    {"id": "b", "name": "Some other name"}]
}

我该如何解决这个问题?我该如何调试呢?

编辑:更新了有关记录数的信息

【问题讨论】:

  • 如果你从控制台Ext.getCmp('yourlistview').getStore().reload(),你能看到XHR返回吗?
  • @Brandon - 当我运行它时,我返回未定义,但通过网络发出了正确的请求(根据 firebug)。
  • 把xtype改成grid还能用吗? ;)
  • 哦,如果您在 Internet Explorer 中并且在字段和列中有尾随逗号,则它可能会损坏。 (可能不是问题)
  • 哦,只要确保所有元素的高度都设置得足够高。高度:123 像素。从控制台你可以 Ext.getCmp('viewid').setHeight(200) 吗?

标签: data-binding extjs jsonstore


【解决方案1】:

你可以试试这样的商店吗:

            store: objPlanManagerStore = new Ext.data.Store({
                autoLoad: true,
                proxy: new Ext.data.HttpProxy({
                    url: '/your/url',
                    method: 'POST'
                }),
                reader: new Ext.data.JsonReader({
                    root: 'plans',
                    id: 'id',
                    fields: ['id', 'name', 'descr', 'tname', 'type', 'recurring']
                }),
                listeners: {
                    loadexception: function() {
                        Ext.Msg.alert('Title', 'msg');
                    }
                }
            });

(只是从我的一些代码中粘贴)

编辑:考虑一下,商店似乎不是问题。

【讨论】:

  • 也正确请求数据,但我看不到任何结果。没有出现异常窗口。
  • 接受为答案。有关 Orbit 的真实答案,请查看问题 cmets。
猜你喜欢
  • 2014-07-20
  • 1970-01-01
  • 2011-12-11
  • 2013-12-07
  • 1970-01-01
  • 1970-01-01
  • 2014-08-07
  • 2014-10-10
  • 2012-11-16
相关资源
最近更新 更多