0

我正在尝试将 json 文件加载到列表中。谁能看到我做错了什么?我没有错误。

数据.js:

Ext.regModel('Contact', {
    fields: ['bandName', 'playDate']
});

ListDemo.ListStore = new Ext.data.Store({
    model: 'Contact',
    sorters: 'bandName',
    getGroupString : function(record) {
        return record.get('bandName')[0];
    },

    /*data: [
        { bandName: "Bandname",      playDate: "Thursday 20:00" }
    ]*/

    proxy: {
        type: 'scripttag',
        url: 'http://domain.com/artists.json',
        reader : {
            type : 'json',
        },
        autoLoad: true
    }
});

索引.js:

ListDemo = new Ext.Application({ name: "ListDemo",

launch: function() {

    ListDemo.detailPanel = new Ext.Panel({
        id: 'detailpanel',
        tpl: 'Hello, {bandName}!',
        dockedItems: [
            {
                xtype: 'toolbar',
                items: [{
                    text: 'back',
                    ui: 'back',
                    handler: function() {
                        ListDemo.Viewport.setActiveItem('disclosurelist', {type:'slide', direction:'right'});
                    }
                }]
            }
        ]
    });

    ListDemo.listPanel = new Ext.List({
        id: 'disclosurelist',
        store: ListDemo.ListStore,
        itemTpl: '<div class="contact">{bandName}<br /><span style="font-size:12px;">{playDate}</span></div>',
        grouped: true,
        onItemDisclosure: function(record, btn, index) {
            ListDemo.detailPanel.update(record.data);
            ListDemo.Viewport.setActiveItem('detailpanel');
        }
    });

    ListDemo.Viewport = new Ext.Panel ({
        fullscreen: true,
        layout: 'card',
        cardSwitchAnimation: 'slide',
        items: [ListDemo.listPanel, ListDemo.detailPanel]
    });

}
});

我的 json 文件:

[
    { "id": 1, "bandName": "Moe", "playDate": "Thursday" },
    { "id": 2, "bandName": "Larry", "playDate": "Thursday" },
    { "id": 3, "bandName": "Curly", "playDate": "Thursday" }    
]

谁能看到我做错了什么?

4

2 回答 2

0

您应该使用 Chrome 浏览器和 Chrome 开发者工具来调试您的代码。您的 json 文件是正确的。

于 2012-04-20T09:28:13.987 回答
0

您的 JSON 文件是数组格式。添加一个以该数组为值的节点,然后将 Sencha Touch 文件中的数据节点(代理的)设置为该节点。JSON 如下所示:

"data": [
    { "id": 1, "bandName": "Moe", "playDate": "Thursday" },
    { "id": 2, "bandName": "Larry", "playDate": "Thursday" },
    { "id": 3, "bandName": "Curly", "playDate": "Thursday" }    
]
于 2012-04-20T07:13:59.040 回答