我们使用DataView来显示一系列按钮。数据来自商店,其中的每个模型都包含按钮的背景颜色。我可以更改按钮的文本,但是如何根据模型中的值更改背景颜色?Sencha Touch:动态按钮背景
这是ButtonData型号:
Ext.define('Sencha.model.ButtonData', {
extend: 'Ext.data.Model',
config: {
fields: [
{name: 'text', type: 'auto'},
{name: 'color', type: 'auto'}
]
}
});
基于这个例子http://www.sencha.com/blog/dive-into-dataview-with-sencha-touch-2-beta-2 我有这个配置一个DataItem的:
config : {
dataMap: {
getButton : { setText: 'text'}, // works!
//problem is here: how do I set the background color based on the 'color'
// member form the 'ButtonData' model?
},
button: {
ui: 'plain'
}
}
所以问题是如何设置基于“颜色”成员的背景颜色形成“ButtonData”模型?
THX,
马腾
最后我们使用了一种类似的方法:我们从Button中派生一个类并为其添加一个setColor函数来更改颜色。 Thx为答案。 – Maarten