繁体   English   中英

ember js对if语句传递参数的动作

[英]ember js action on if statement passing a parameter

我只需要将参数传递给特定路线的余烬动作即可。

{{#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}}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM