簡體   English   中英

ExtJS存儲,無法將數據加載到網格

[英]ExtJS store, cannot load data to grid

控制台很清楚。 網格為空(僅顯示列標題)。 如何檢查數據是否正確加載到存儲中? 在我看來,商店的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'    
});

移動

model: 'Clients',
storeId: 'storeClients'

進入商店定義,並擺脫商店創建調用。 商店將自動創建。

為什么要覆蓋商店構造函數? 如果確實需要執行此操作,則應將this.callParent(arguments)添加到構造函數中,否則原始的構造函數(會執行很多操作)將不會運行。

你只需要改變

 store: Ext.getStore('storeClients')

為此:

store: 'Clients'

我認為您在創建商店時需要寫字段

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM