2013-07-14 102 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']