我產生RecordArray,該模型的一個子集,控制器裏面,但我不知道如何與在HTML車把{{#each}}
顯示。如何顯示從控制器更新的ember.js模型/ RecordArray?
下面的答案可能還展示瞭如何在同一頁相同的控制器ember.js 2 /多個模型中顯示。
我產生RecordArray,該模型的一個子集,控制器裏面,但我不知道如何與在HTML車把{{#each}}
顯示。如何顯示從控制器更新的ember.js模型/ RecordArray?
下面的答案可能還展示瞭如何在同一頁相同的控制器ember.js 2 /多個模型中顯示。
需要首先設置一個變量與包含RecordArray控制器。然後你可以在該變量上調用each
。
App.YourController = Ember.ArrayController.extend({
...
doSearch: function(){
var theRecordArray = App.Model.find({theAttribute: blah});
this.set('variableOfYourChoice', theRecordArray);
}
});
而在HTML:
{{#each variableOfYourChoice}}
<li>{{theAttribute}}</li>
{{/each}}
看到它在this jsbin這說明RecordArray作爲搜索結果運行。
因此,可以說上述ItemsController有項目列表,但你只是想列出你的模板中的特殊項目。添加計算的屬性,它過濾像這樣的項目:
App.ItemsController = Ember.ArrayController.extend({
specialItems: function() {
var items = this.get('content');
return items.filterProperty('isSpecial')
}.property('[email protected]');
});
然後引用該財產在你的模板:
{{#each item in specialItems}}
{{item.title}}
...
{{/each}}