传递参数的if语句上的ember-js操作

ember js action on if statement passing a parameter

本文关键字:ember-js 操作 语句 if 参数      更新时间:2023-09-26

我只需要将一个参数传递给特定路由的成员操作。

{{#if isSelected 'filters' filter.id}}class="active"{{/if}}

我在app.js文件中的动作路线定义看起来像这个

App.FooRoute = Ember.Route.extend({
  model: (...),
  actions : {
    (...),
    'isSelected' : function(table,obj) {
      return this.store.find(table,obj).get('selected');
    }
  }
});

但我得到了Uncaught Error: Assertion Failed: You must pass exactly one argument to the if helper

我不想为此编写帮助程序,因为代码会更好地组织。。。

如何做到这一点?

答案是:我不能。将一个参数传递给if语句,控制台显示

Uncaught Error: Assertion Failed: You must pass exactly one argument to the if helper 

认为,这将是一个很好的功能

编辑我用这几行代码安排了我的需求。

Ember.ObjectController.extend({
  actions : { 
    selectItem : function(table,item){
      this.store.find(table,item.id).then(function(obj){
        obj.set('selected',!obj.get('selected'));
      console.log(obj.get('selected'));
        obj.save();
      });
    },
    selectAll : function(table){
      this.store.find(table).then(function(obj){
        obj.forEach(function(obj){
          obj.set('selected',true);
          obj.save();
        });
      });
    }
}
});

和我的车把(一部分)

{{#each obj in model.objs}}
  <dd {{bind-attr class="obj.selected:active"}}><a {{action "selectItem" 'filter' obj}}>{{obj.name}}</a></dd>
{{/each}}

尝试对象:

{{#if isSelected {table: 'filters', id: filter.id} }}class="active"{{/if}}