【问题标题】:My store is not populating with a simple model data我的商店没有填充简单的模型数据
【发布时间】:2015-02-21 23:57:31
【问题描述】:

我有一个基本的 users.json 文件、一个用户模型和一个用户存储。当我调用 getCount() 时,商店的大小为 0。

我最初的想法是为加载事件添加一个监听器。但是,即使只是调用 getStore() 也会返回空数据。

你能看出我是不是搞错了?

    {
    "users":[
        {
            "name": "Mike Henderson",
        },
        {
            "name": "Sally Michael",
        },
        {
            "name": "Rory Muldoon",
        }
    ]
}


Ext.define('TP.model.User', {
    extend: 'Ext.data.Model',

    config: {
        fields: ['name']
    }
});

Ext.define('TP.store.Users', {
    extend: 'Ext.data.Store',

    config:{
        autoload: true,
        model: 'TP.model.User',
        storeId: 'Users',
        proxy : {
            type: 'ajax',
            url: 'data/users.json',
            reader: {
                rootProperty: 'users',
                type: 'json'
            }
        }
    }
});

Ext.application({
    name: 'TP',

    views: ['Main'],

    models:['User'],

    stores:['Users'],

    launch: function() {
        // Destroy the #appLoadingIndicator element
        Ext.fly('appLoadingIndicator').destroy();

        // Initialize the main view
        Ext.Viewport.add(Ext.create('TP.view.Main'));

        Ext.getStore('Users').on('load', this.onStoreLoad, this);
        console.log(Ext.getStore('Users').getCount());

    },

    onStoreLoad: function(self, records, success, operation) {
        console.log("loaded store");
    }

});

【问题讨论】:

    标签: extjs sencha-touch-2 store


    【解决方案1】:

    我终于找到了解决办法,就是一个简单的错字。

    在商店配置中 - 自动加载需要自动加载(大写 L)

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-08-28
      • 2016-06-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多