2013-07-14 68 views
1

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

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); 
    } 
}); 

这里是商店(模型包含只是延长和领域CONFIGS):

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'  
}); 

回答

1

移动

model: 'Clients', 
storeId: 'storeClients' 

进店的定义,并摆脱创建商店电话。商店将自动创建。

+0

您的意思是说Ext.getStore('storeClients')会自动创建商店类的一个实例吗? – paperstreet7

+1

是的。商店实例将自动创建。甚至在你调用getStore()之前。 – sha

1

你为什么重写商店构造函数? 如果您确实需要这样做,您应该将this.callParent(arguments)添加到构造函数中,否则最初的构造函数(它会执行很多操作)将无法运行。

0

你只需要改变

store: Ext.getStore('storeClients') 

这样:

store: 'Clients' 
0

我认为你需要在创建店里写。 即

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