[英]Handlebars template for Ember.js objects grouped by two
我的數據集中在集合中,我需要將它們渲染到模板中。 將數據分為兩部分時如何獲得結果? 我需要像這樣對它們進行排序:
._______________________
| 1 | 3 | 5
|___|___|_______________
| 2 | 4 | and so on...
|___|___|_______________
我已經為每個1 + 2、3 + 4,...對創建了垂直div元素,以對此類項進行樣式設置。 如何使用手把渲染到這樣的網格中? 我所能做的就是:
{{#each App.myController}}
... render item ...
{{/each}}
首先,如果可能的話,我會嘗試在CSS中執行此操作。
如果不是,最好的選擇是將計算屬性添加到控制器中,然后將它們成對分組,並以此方式進行操作。 像這樣:
{{#each App.myController.pairedContent}}
<!-- view for content.firstObject -->
<!-- view for content.lastObject -->
{{/each}}
App.MyController = Ember.ArrayController.extend({
pairedContent: ( function(){
return this.get('content').reduce( function(array, object, index){
if(index % 2){
array.get('lastObject').pushObject(object)
}
else{
array.pushObject(Ember.A([object]))
}
return array
}, Ember.A())
}).property('content')
})
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.