投放本站广告请联系:
extjscn#126.com
List在MVC下显示store数据的问题
如果采用MVC模式定义了Store和对应的model,分别为:
Ext.define('hcx.store.ContactStore',{
extend : 'Ext.data.Store',
xtype : 'hStore',
requires : ['hcx.model.Contact'],
config: {
model : 'hcx.model.Contact',
sorters : 'lastName',
grouper : {
groupFn : function(record){
return record.get('lastName')[0];
}
},
data : [
{ firstName: 'Tommy', lastName: 'Maintz' },
{ firstName: 'Rob', lastName: 'Dougan' },
{ firstName: 'Ed', lastName: 'Spencer' },
{ firstName: 'Jamie', lastName: 'Avins' }
]
}});
View Code
Ext.define('hcx.model.Contact',{
extend : 'Ext.data.Model',
xtype : 'hContact',
config : {
fields: ['firstName', 'lastName']
}
});
如果参照官方文档的例子,很容易会得出以下写法的List定义
Ext.define('hcx.view.Member',{
extend : 'Ext.dataview.List' ,
fullscreen: true,
requires : ['hcx.store.ContactStore'],
config : {
title : 'memCard',
itemTpl: '<div class="contact">{firstName} <strong>{lastName}</strong></div>',
store : 'hcx.store.ContactStore'
grouped : true}
});
这样就会出现The specified Store cannot be found 的警告。并且store中的数据并没有显示到页面上。
这是因为我们在store的引用中使用了: store : 'hcx.store.ContactStore'
hcx.store.ContactStore仅仅是store的类名,我们并没有指定任何具体的store,所以会出现这个警告。
我觉得奇怪的反而是,这个不应该是一个警告,应该升级为一个错误可能会更加适合。
所以我们需要修改为:
store : {xtype : 'hStore'}
这里使用xtype对store进行动态加载,也就是说创建了具体的store放入list中进行显示
作者:Ever
原文:http://www.cnblogs.com/evermaze/archive/2013/03/17/listwarn.html
- 关键字:
- 要发表评论,请先登录

