无法从gridpanel extjs4 MVC中的商店加载数据

时间:2014-08-27 08:55:32

标签: model-view-controller extjs4 load store gridpanel

我的MVC如下:

MODEL:

Ext.define('test.model.mdlPerson', {
    extend: 'Ext.data.Model',
    fields: [
        { name: 'name' },
        { name: 'surname' }, 
        { name: 'email' }
    ]
}); 

STORE:

Ext.define('test.store.Person', {
    extend: 'Ext.data.ArrayStore',
    model: 'test.model.mdlPerson',
    data: [
        { name: 'Edddd', surname: 'dfasd', email: 'ed@sencha.com' },
        { name: 'Tommy', surname: 'dfgdfgdfg', email: 'tommy@sencha.com' }
    ],
    storeId: 'Person'
});

GridPanel视图:

Ext.define('test.view.GridPanel', {
    extend: 'Ext.grid.Panel',
    title: 'The GridPanel',
    alias: 'widget.gridpanel',
    itemId: 'gridPanelId',
    store: 'Person',
    initComponent: function() {
        columns : [
                { text: 'Name', dataIndex: 'name' },
                { text: 'Surname', dataIndex: 'surname' },
                { text: 'E-mail', dataIndex: 'email' }
            ]
        this.callParent(arguments);
    }
});

控制器:

Ext.define('test.controller.GridPanel', {
    extend: 'Ext.app.Controller',
    stores: ['Person'],
    models: ['mdlPerson'],
    views: ['GridPanel'],
    refs: [{
        ref: 'gridpanel',
        selector: 'gripanel'
    }]
});

问题是商店无法加载。我也试过了getStore()方法,但没有出现。有人在这帮忙!非常感谢!!!

2 个答案:

答案 0 :(得分:0)

你不需要控制器。 当硬编码数据时会自动加载。

你有app.js吗? 如果不在这里

Ext.application({
    models: [
        'mdlPerson'
    ],
    stores: [
        'Person'
    ],
    views: [
        'GridPanel'
    ],
    name: 'test',

    launch: function() {
        Ext.create('test.view.GridPanel', {renderTo: Ext.getBody()});
    }

});

答案 1 :(得分:0)

你可以替换extend:' Ext.data.ArrayStore'  至 extend:' Ext.data.Store'然后试试......