【问题标题】:Extjs not loading data from storeExtjs 不从商店加载数据
【发布时间】:2015-11-08 15:57:32
【问题描述】:

我正在学习 extJS 并尝试按照 thisthat 指南创建简单的应用程序。

我的 app.js 文件:

sstore = new Ext.data.Store({
    autoLoad: true,
    fields: ['firstName', 'lastName', 'educationId', 'townId'],
    proxy: {
        type: "ajax",
        url: "data",
        reader: {
            type:"json",
            root: "users"
        }
    }
});


Ext.application({
    name: 'Application',
    autoCreateViewport: true,
    controllers: ['MainController']
});

Viewport.js

Ext.define('Application.view.Viewport', {
    extend: 'Ext.container.Viewport',
    layout: { type: "vbox", align: 'stretch' },

    items :  [{
        xtype: 'mainList',
        autoScroll: true
    }]
});

List.js

Ext.define('Application.view.List', {
    extend: 'Ext.grid.Panel',
    alias : 'widget.mainList',
    title : 'Users',

    store: sstore,     // ***** LOOK HERE PLEASE *****
    //store: 'Users',

    columns: [
        { header: 'Имя',  dataIndex: 'firstName' },
        { header: 'Фамилия', dataIndex: 'lastName' },
        { header: 'Образование', dataIndex: 'educationId'},
        { header: 'Город', dataIndex: 'townId'}
    ]
});

商店(Users.js):

Ext.define('Application.store.Users', {
    extend: 'Ext.data.Store',    
    storeId: 'usersStore',    
    //model: 'Application.model.User',    
    fields: ['firstName', 'lastName', 'educationId', 'townId'],    
    autoLoad: true,    
    proxy: {
        type: 'ajax',
        url: 'data',
        reader: {
            type: 'json',
            root: 'users'
        }
    },    
    onProxyLoad: function (aOperation) {
        console.log('From store');
        console.log(aOperation);
    }

});

当我在我的 List.js 文件中更改 store: 'Users' 上的 store: sstore 时,它不会加载任何数据,而是在 app.js 文件中创建存储在 sstore 变量中,它工作正常。

我尝试过但没有帮助:

  • 使用内存代理,
  • 使用store: Ext.data.StoreManager.lookup('usersStore'),
  • 后端数据没问题(因为sstore工作正常)

我可以看到来自 Users.js 的商店正在加载(因为来自onProxyLoad 函数的控制台输出)。

这是我在浏览器中看到的:

完整的js应用生活here

我的查看文件是here

我正在使用 extJS 4.2

【问题讨论】:

    标签: javascript extjs extjs4


    【解决方案1】:

    这真是愚蠢。问题出在onProxyLoad 函数中。当我从商店应用程序中删除它时,它按预期工作。

    【讨论】:

    • 是的,通常最好不要覆盖私有成员,但如果你这样做,你可以在旧版本的框架中包含 this.callParent(arguments);this.callOverridden(arguments); 行 - 在函数内部确保保留默认行为。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2020-04-14
    • 1970-01-01
    • 1970-01-01
    • 2015-05-26
    • 2013-03-17
    • 2012-03-11
    • 1970-01-01
    相关资源
    最近更新 更多