【发布时间】:2014-02-04 07:13:27
【问题描述】:
我正在尝试在 Ember.js 中实现“分组依据”功能,但事实证明它比我最初想象的要困难。
[{date: '2014-01-15T16:22:16-08:00', message: 'Tidal wave occurred'},
{date: '2014-01-15T05:00:16-08:00', message: 'Tornado destroyed town'},
{date: '2014-01-13T14:22:16-08:00', message: 'Volcanic eruption, likely'},
{date: '2014-01-13T16:24:16-08:00', message: 'Ice shelf calving off completely'},
{date: '2014-01-11T11:27:26-08:00', message: 'Mother-in-law visiting'}]
我正在寻找类似这样的最终输出:
Today
----------
4:22 pm - Tidal wave occurred
5:00 am - Tornado destroyed town
Monday
----------
2:22 pm - Volcanic eruption, likely
...etc., etc.
现在这个数据被绑定到一个 ArrayController。每个对象都有一个计算属性来获取“年/月/日”进行分组比较。
var ActivityController = Em.ArrayController.extend({
groupedResults: function () {
var result = [];
//Iterate over each item in the list, but do what with it?
this.get('content').filter(function (item) {
});
return result;
}.property('content.[]')
});
关于实现这一点的最佳方法的任何提示? Ember 附带 filterBy 和 mapBy,但没有 groupBy。
【问题讨论】:
标签: ember.js