【问题标题】:Extjs Json load without RootExtjs Json 加载没有 Root
【发布时间】:2014-08-03 07:46:42
【问题描述】:

我的问题是我得到的 json 没有根。我可以让商店加载 URL 并返回 JSON,但商店数据是空的,回调中没有显示任何内容。

Json:
[
{
    "symbol": "GM"
},
{
    "symbol": "GA"
}
]

模型和商店:

Ext.define('Symbol', {
extend: 'Ext.data.Model',
fields: ['symbol']
});


Ext.define('Doc.store.symbol', {
extend: 'Ext.data.Store',
model: 'Symbol',
proxy: {
    type: 'jsonp',
    url: 'datasource/symbol',
    reader: {
        type: 'json',
        model: 'symbol'
    },
}
});

我也尝试删除根目录,但商店或回调中没有返回任何内容。我的 googlefu 在没有 root 的情况下在 json 上没有任何好处。

【问题讨论】:

  • 你确定你应该使用 JSONP 吗?

标签: json extjs


【解决方案1】:

根应定义为空白root:''

这是一个演示正确设置的代码:

       Ext.define('boomer', {
            extend:'Ext.data.Model',
            fields: ['symbol'],
            proxy: {
                type: "ajax",
                url: "data.json",
                extraParams: {
                },
                reader: {
                    type: "json",
                    root: "",
                    successProperty: "success"
                }
            }
        });
        var store = Ext.create('Ext.data.Store',{
            model: 'boomer',
        });
        store.load({
            callback:function(){
                Ext.Msg.alert('Store Items', store.data.items.length);
                console.log(store.data.items);
            }
        });

Here is a fiddle demonstrating working code.

【讨论】:

    【解决方案2】:

    扩展Ext.data.reader.Json 以调整您的响应。稍后在代理阅读器中使用它。

    there is a answer here

    【讨论】:

      猜你喜欢
      • 2023-03-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-08-10
      • 1970-01-01
      相关资源
      最近更新 更多