0
我有一個Ember.Select根據特定角色過濾模型。目前,應用程序啓動模型的全部內容時會顯示,但我只想在應用濾鏡時顯示模型。我對如何做到這一點毫無頭緒。如何僅返回Emberjs中的過濾模型?
這裏是我的問題控制器,
App.TwodController = Ember.ArrayController.extend({
//filteredContent : null,
sortProperties: ['firstname'],
sortAscending: true,
selectedExperience : null,
experience : [{
exp : "1"
}, {
exp : "2"
}, {
exp : "3"
}, {
exp : "4"
}, {
exp : "5"
}],
selectedDesignation : null,
filterDesignation : function() {
var designation = this.get('selectedDesignation.designation');
var filtered = this.get('content').filterProperty('designation', designation);
this.set("filteredContent", filtered);
}.observes('selectedDesignation'),
designations : [{
designation : "Design",
id : 1
}, {
designation : "Writer",
id : 2
}, {
designation : "Script",
id : 3
}, {
designation : "Storyboard",
id : 4
}, {
designation : "Workbook",
id : 5
}],
actions : {
filterExperience : function() {
var experience = this.get('selectedExperience.exp');
var filtered = this.get('content').filterProperty('experience', experience);
this.set("filteredContent", filtered);
},
refresh : function() {
var refresh = this.get('content');
this.set("filteredContent", refresh);
}
},
filteredContent : function() {
var searchText = this.get('searchText'), regex = new RegExp(searchText, 'i');
return this.get('model').filter(function(item) {
var fullname = item.firstname + item.lastname;
return regex.test(fullname);
});
}.property('searchText', 'model')
});
此外,還有一個我有問題,我不能夠按升序排列。我需要在代碼中做什麼改變才能達到理想的效果?
這裏是完整的JSBin如果任何人有興趣。
謝謝!那就是訣竅,那麼我的升序問題呢? –
哦,對不起。查看我的答案更新。您可能還想從您的控制器中移除您的'filteredContent'計算屬性。 – chopper
雖然這是綁定到文本框,它不應該有任何效果嗎? –