简体   繁体   English

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

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

I just need to pass a parameter to an ember action of a specific route. 我只需要将参数传递给特定路线的余烬动作即可。

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

my action route definition in the app.js file looks like this 我在app.js文件中的动作路线定义如下所示

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

but I got Uncaught Error: Assertion Failed: You must pass exactly one argument to the if helper 但是我遇到了Uncaught Error: Assertion Failed: You must pass exactly one argument to the if helper

I don't want to write a helper for this because the code would be better organized... 我不想为此写一个助手,因为代码会更好地组织起来...

how to do this? 这个怎么做?

the answer is: I can't. 答案是:我不能。 passing one argument to the if statement the console shows 向控制台显示的if语句传递一个参数

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

it would be a nice feature to have, thought 想,这将是一个不错的功能

EDIT I have arranged my needs with this lines of code. 编辑我已经用这行代码安排了我的需求。

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();
        });
      });
    }
}
});

and my handlebar (a portion of it) 和我的车把(一部分)

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