![](/img/trans.png)
[英]Ember.js - how to pass an array or a model from the controller to the template?
[英]Ember.js: How to dispaly only a part of model in template?
在模板中:
{{#each displayVideos}}
Index: {{_view.contentIndex}}
{{/each}}
它將顯示模型中的所有項目。
但我想只顯示一些取決於索引的項目(例如:如果索引%2 = = 0則顯示項目)。
有什么想法嗎? 謝謝
在控制器中創建一個計算屬性,它只返回每隔一行,然后迭代它...
就像是:
App.MyController = Ember.ObjectController.extend({
everySecondRow: function() {
//code to only return every second row
}.property('model')
});
然后在你的模板中:
{{#each controller.everySecondRow}} ... {{/each}}
我們也可以使用助手。 這是一個例子 。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.