Extjs没有从商店加载数据

时间:2015-11-08 15:57:33

标签: javascript extjs extjs4

我正在学习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: sstore store: 'Users'时,它没有加载任何数据,但是在app.js文件中创建了存储,该文件存在于sstore变量中,它可以正常工作好。

我尝试过但没有帮助:

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

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

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

enter image description here

完整的js app生活here

我的观看文件是here

我正在使用extJS 4.2

1 个答案:

答案 0 :(得分:0)

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