[英]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.