我正在尝试按照这里给出的小猫示例 http://www.sencha.com/blog/dive-into-dataview-with-sencha-touch-2-beta-2#comment_form
我有复杂的组件,其中我的数据的一个属性是对象列表。我正在使用setItems方法将列表对象映射到Ext.Container。但是,它似乎不起作用。在警报点,我将对象定义为未定义。但是,如果我将setItems更改为setText,那么我将获得该对象的字符串表示形式。有没有人对我缺少的东西有任何建议?
Ext.define('MyListItem', {
extend: 'Ext.dataview.component.DataItem',
requires: ['Ext.Container'],
xtype: 'mylistitem',
config: {
sponsor: true,
dataMap: {
getSponsor: {
setItems: 'sponsor'
}
}
},
applySponsor: function(config) {
// I put an alert here to see if I get getSponsor() but the object I get here is undefined
alert(this.getSponsor());
return Ext.factory(config, Ext.Container, this.getSponsor());
},
updateSponsor: function(newNameButton, oldNameButton) {
if (oldNameButton) {
this.remove(oldNameButton);
}
if (newNameButton) {
this.add(newNameButton);
}
},
onSponsorTap: function(button, e) {
var sponsors = record.get('sponsor');
//my specific action
}
});
Ext.define('MyApp.model.Sponsors', {
extend: 'Ext.data.Model',
xtype:'Sponsors_m',
config: {
fields: [
{name: 'level', type: 'auto'},
{name: 'id', type: 'int'},
{name: 'sponsor', type: 'Sponsor'}
]
}
});
Ext.define('MyApp.model.Sponsor', {
extend: 'Ext.data.Model',
xtype:'Sponsor_m',
config: {
fields: [
{name: 'name', type: 'auto'},
{name: 'image', type: 'auto'},
{name: 'url', type: 'auto'},
{name: 'description', type: 'auto'}
]
}
});
答案 0 :(得分:0)
嗯...
您的模型中没有任何名为“赞助商”的字段
config: {
sponsor: true,
dataMap: {
getSponsor: {
***setItems: 'sponsor'*** //this supposed to map your component to the datafield
}
}
},
尝试将粗体字体更改为您的字段名称(setItems:'name')
如果我没弄错的话,对于更新方法的参数命名有严格的规则,即: ***以“赞助商”为例进行配置名称
newSponsor,oldSponsor
所以赞助商的更新方法应该是:
updateSponsor: function(**newSponsor**, **oldSponsor**) {
if (oldSponsor) {
this.remove(oldSponsor);
}
if (newSponsor) {
this.add(newSponsor);
}
},