Dario Rusignuolo
Dario Rusignuolo

Reputation: 2186

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.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

I don't want to write a helper for this because the code would be better organized...

how to do this?

Upvotes: 1

Views: 2071

Answers (2)

Dario Rusignuolo
Dario Rusignuolo

Reputation: 2186

the answer is: I can't. passing one argument to the if statement the console shows

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

Upvotes: 1

Alcadur
Alcadur

Reputation: 685

Try with object:

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

Upvotes: 0

Related Questions