2013-08-16 45 views

回答

0

需要首先設置一個變量與包含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作爲搜索結果運行。

1

因此,可以說上述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}} 
相關問題