我們使用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