JSON数据未加载 - ExtJS

时间:2013-12-06 18:12:53

标签: json extjs store

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

应用程序/数据/ 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' }, 

有什么想法吗? 干杯!

1 个答案:

答案 0 :(得分:1)

这是无效的JSON:

  1. 标签应包含在引号中,例如"name"。你也应该使用双引号,而不是单引号。
  2. 您无法在JSON中使用new Date(),它无效。查看Ext.data.Field以及dateFormat参数周围的信息。您将日期作为字符串发回,并为其指定格式,以便Ext可以为您解析它。
  3. 此外,您缺少字段定义。您需要创建一个Ext.data.Model子类,其中包含您将在商店中使用的字段。

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