ExtJS存储,无法将数据加载到网格中

时间:2013-07-14 06:00:41

标签: javascript json extjs extjs4

控制台很清楚。网格为空(仅显示列标题)。如何检查数据是否正确加载到商店?在我看来,商店的autoLoad方法不会以某种方式触发。这是网格:

Ext.define('NameSpace.view.Clients', {
    requires: [
        'Ext.tree.Panel',
        'Ext.grid.Panel'        
    ],
    extend: 'Ext.tab.Panel',
    title: 'Clients',
    alias: 'widget.viewClients',    

    items: [
        {
            xtype: 'panel',
            title: 'All Clients',            

            layout: {
                type: 'hbox',
                align: 'stretch'
            },

            items: [
                {
                    xtype: 'treepanel',
                    title: 'Tree Panel',
                    width: 200,
                    resizable: true                    
                },
                {
                    xtype: 'gridpanel',
                    title: 'Clients List',

                    store: Ext.getStore('storeClients'),

                    flex: '1',
                    columns: [                        
                        { text: 'Name', dataIndex: 'first_name' },
                        { text: 'Last Name', dataIndex: 'last_name' },
                        { text: 'Phone Number', dataIndex: 'phone' }
                    ]
                }
            ]
        }
    ],

    initComponent: function () {
        this.callParent(arguments);
    }
});

这是商店(模型只包含扩展和字段配置):

Ext.define('NameSpace.store.Clients', {
    extend: 'Ext.data.JsonStore',

    proxy: {
        type: 'ajax',
        url: 'http://test.local/client',
        reader: {
            type: 'json',
            root: 'records' 
        }
    },

    autoLoad: true,

    constructor: function (config) {
        this.initConfig(config);
    }
});

Ext.create('NameSpace.store.Clients', {
    model: 'Clients',
    storeId: 'storeClients'    
});

4 个答案:

答案 0 :(得分:1)

移动

model: 'Clients',
storeId: 'storeClients'

进入商店定义,并摆脱商店创建调用。商店将自动创建。

答案 1 :(得分:1)

为什么要覆盖商店构造函数? 如果你确实需要这样做,你应该将this.callParent(arguments)添加到构造函数中,否则原始构造函数(它会做很多事情)不会运行。

答案 2 :(得分:0)

您只需要更改

 store: Ext.getStore('storeClients')

To This:

store: 'Clients'

答案 3 :(得分:0)

我认为您在创建商店时需要编写字段。 即。

fields:[ 'first_name', 'last_name', 'phone']