我有一个Ember.js ArrayController,我正在尝试创建一个生成访问总和的计算属性,但我被卡住了:
带排序数组的控制器
App.SpreadsheetController = Ember.ArrayController.extend({
sortProperties: ['visits'],
sortAscending: false,
allVisits: function() {
var visits = this.get('content.@each.visits').toArray();
visits.forEach(function(val) {
// sum all visits
);
return visits;
}.property('content.@each.visits'),
actions: {
orderAsc: function (){
this.set('sortAscending', true);
},
orderDesc: function (){
this.set('sortAscending', false);
},
}
});
索引.html
Without each: {{allVisits}} //show
{{#each}}
{{allVisits}} //don't show
{{/each}}
为什么不显示每个访问中的所有访问?任何解决方案?
它必须是
{{#each allVisits}}
{{this}}
{{/each}}
由于 {{each}}
循环中的本地上下文是正在迭代的当前元素,因此该元素将没有 allVisits 属性
我找到了适合我的解决方案
{{#each}}
{{controller.allVisits}}
{{/each}}
顺便说一下谢谢