Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/466.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/ember.js/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 余烬组件绑定属性className不';不变_Javascript_Ember.js_Handlebars.js - Fatal编程技术网

Javascript 余烬组件绑定属性className不';不变

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

我正在尝试做一件非常简单的事情,但到目前为止我还没能做到。可能是我在做傻事

在圆圈中单击可打开和关闭帖子。您可以看到警报消息即将发出,参数正在更新,但是我无法更改类名

这是JS垃圾桶:

我错过了什么


干杯

因此基本上您应该在组件上使用类绑定

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']