Javascript 余烬组件绑定属性className不';不变
我正在尝试做一件非常简单的事情,但到目前为止我还没能做到。可能是我在做傻事 在圆圈中单击可打开和关闭帖子。您可以看到警报消息即将发出,参数正在更新,但是我无法更改类名 这是JS垃圾桶: 我错过了什么Javascript 余烬组件绑定属性className不';不变,javascript,ember.js,handlebars.js,Javascript,Ember.js,Handlebars.js,我正在尝试做一件非常简单的事情,但到目前为止我还没能做到。可能是我在做傻事 在圆圈中单击可打开和关闭帖子。您可以看到警报消息即将发出,参数正在更新,但是我无法更改类名 这是JS垃圾桶: 我错过了什么 干杯 因此基本上您应该在组件上使用类绑定 App.ListItemComponent = Ember.Component.extend({ tagName:'tr', classNameBindings: ['isPublished:on:off'], isPublished
干杯 因此基本上您应该在组件上使用类绑定
App.ListItemComponent = Ember.Component.extend({
tagName:'tr',
classNameBindings: ['isPublished:on:off'],
isPublished: function() {
return this.get('published');
}.property('published'),
actions: {
publish: function() {
this.toggleProperty('published');
}
}
});
JSBIN:
您也可以使用
类名添加多个类
classNames: ['class-name-1'],
classNameBindings: ['isSomethingTrue:class-name-2:class-name-3']
这里有更多参考资料:哦,伙计,就是这样!我以前尝试过,但标记名错误。非常感谢!只需提醒一下Ember.Object
上的toggleProperty
方法:this.toggleProperty('published')
App.ListItemComponent = Ember.Component.extend({
tagName:'tr',
classNameBindings: ['isPublished:on:off'],
isPublished: function() {
return this.get('published');
}.property('published'),
actions: {
publish: function() {
this.toggleProperty('published');
}
}
});
classNames: ['class-name-1'],
classNameBindings: ['isSomethingTrue:class-name-2:class-name-3']