用例是我试图使用Ember.Select过滤模型,只要用户点击按钮,模型就会根据'Designation'属性进行过滤。
这是我的Ember.Select:
{{view Ember.Select
contentBinding="designations"
optionValuePath="content.id"
optionLabelPath="content.designation"
selectionBinding="roles.selectedDesignation"}}
<button {{action 'filter'}}>Filter</button>
这就是我在App.js中所做的事情,
App.TwodController = Ember.Controller.extend({
filteredContent : Ember.computed.oneWay("content"),
selectedDesignation : null,
designations : [{
designation : "Design",
id : 1
}, {
designation : "Writer",
id : 2
}],
actions : {
filter : function() {
var designation = this.get('roles.selectedDesignation');
var filtered = this.get('content').filterProperty('designation', designation);
this.set("filteredContent", filtered);
}
}
});
这是完整的JSBin,http://jsbin.com/iPUxuJU/2/edit
我可能在这里缺少什么?
答案 0 :(得分:1)
您在选择装订中缺少某些内容
{{view Ember.Select
contentBinding="designations"
optionValuePath="content.id"
optionLabelPath="content.designation"
selectionBinding="selectedDesignation"}}
<button {{action 'filter'}}>Filter</button>
在控制器逻辑中:
App.TwodController = Ember.Controller.extend({
filteredContent : Ember.computed.oneWay("content"),
selectedDesignation : null,
designations : [{
designation : "Design",
id : 1
}, {
designation : "Writer",
id : 2
}],
actions : {
filter : function() {
var designation = this.get('selectedDesignation.designation');
var filtered = this.get('content').filterProperty('designation', designation);
this.set("filteredContent", filtered);
}
}
});
这是工作jsbin