【问题标题】:JSON data not loading - ExtJSJSON 数据未加载 - ExtJS
【发布时间】:2013-12-07 02:39:03
【问题描述】:

我无法将任何 json 数据加载到我的组合框中。这是我的代码:

app/data/mydata.json

{
    images: [
        {name: 'Image one', url:'/GetImage.php?id=1', size:46.5, lastmod: new Date(2007, 10, 29)},
        {name: 'Image Two', url:'/GetImage.php?id=2', size:43.2, lastmod: new Date(2007, 10, 30)}
    ]
}

在我的 app.js 中

var store4 = new Ext.data.JsonStore({
    // store configs
    storeId: 'myStore',
    autoLoad: true,
    proxy: {
        type: 'ajax',
        url: 'app/data/mydata.json',
        reader: {
            type: 'json',
            root: 'images',
            idProperty: 'name'
        }
    },
});...

我在 app.js 中的组合框

{ xtype: 'combobox', queryMode: 'local', padding: 5,   store: store4, displayField: 'name', typeAhead: true, emptyText: 'JSON', id: 'test' }, 

有什么想法吗? 干杯!

【问题讨论】:

    标签: json extjs store


    【解决方案1】:

    这不是有效的 JSON:

    1. 标签应该用引号括起来,例如"name"。您还应该使用双引号,而不是单引号来引用字符串。
    2. 您不能在 JSON 中使用 new Date(),它无效。查看Ext.data.FielddateFormat 参数周围的信息。您将日期作为字符串发回并给它一个格式,以便 Ext 可以为您解析它。

    另外,您缺少字段定义。您需要使用要在商店中使用的字段创建一个 Ext.data.Model 子类。

    Ext.define('Image', {
        extend: 'Ext.data.Model',
        fields: ['name', 'url', 'size']
    });
    
    var store = new Ext.data.Store({
        model: 'Image',
        // ..
    
    });
    

    【讨论】:

    • 我更改了引号并删除了日期,但我的组合框中仍然没有数据显示
    • 它也通过 JSONLint 进行验证
    • 您还缺少字段定义。
    • 字段定义?那些是什么?
    • 这对你有用吗,因为我无法显示我的数据
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-07-13
    • 2012-08-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多