【发布时间】: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