我想在绑定(bind)后更改 css 类。在 ExtJS5 中可以吗?
我添加了评论。 fiddle : https://fiddle.sencha.com/#fiddle/olc
最佳答案
您的代码中有几个问题:
- cls 无法绑定(bind),因为没有 setCls 方法 - 您可以绑定(bind) 如果需要的话请关闭图标
- 您无法在字符串后添加索引,例如
iconCls:'{ rating}'[0]
- 这在语法上是不正确的 - 如果您定义这样的
rating
公式,则必须运行get函数 -get()
试试这个代码
Ext.define('Fiddle.view.FooModel', {
extend: 'Ext.app.ViewModel',
alias: 'viewmodel.fiddle-foo',
data: {
val: 1
},
formulas: {
rating: function(get) {
get();
return 'hello-world';
}
}
});
Ext.define('Fiddle.view.Foo', {
extend: 'Ext.panel.Panel',
xtype: 'fiddle-foo',
viewModel: {
type:'fiddle-foo'
},
layout: 'hbox',
height: 50,
width: 250,
items: [{
xtype: 'button',
text: 'rating 1',
bind:{
iconCls:'{rating}'
}
}, {
xtype: 'button',
text: 'rating 2',
bind:{
iconCls:'{rating}'
}
}, {
xtype: 'button',
text: 'rating 3',
bind:{
iconCls:'{rating}'
}
}]
});
Ext.application({
name: 'Fiddle',
launch: function() {
new Fiddle.view.Foo({
renderTo: document.body,
width: 400,
height: 400,
title: 'Test'
});
}
});
关于javascript - 如何在 ExtJS5 中使用 ViewModel 绑定(bind)将 Cls 添加到 Button,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30820939/