1
我需要在我的模型上执行嵌套分组才能显示它。在Ember.js中执行嵌套分组
下面是所需的输出我需要:
---- Today ----
-- Thread 1
- Activity 1
- Activity 2
-- Thread 2
-- Activity 1
---- Yesterday ----
-- Thread 1
- Activity 1
- Activity 2
-- Thread 2
- Activity 1
我无法找出一个最佳的方式来实现这一目标。我需要帮助开发一个适当的控制器和视图/模板。
这是我最低限度的应用程序设置fixtures
,以便您对我的模型有更多的了解。
(function($, Ember) {
'use strict';
var App = Ember.Application.create({
rootElement: '#app-container'
});
App.Store = DS.Store.extend({
revision: 13,
adapter: DS.FixtureAdapter
});
App.Thread = DS.Model.extend({
title: DS.attr('string'),
url: DS.attr('string'),
kind: DS.attr('string'),
lastActivityOn: DS.attr('date'),
activities: DS.hasMany('activity')
});
App.Activity = DS.Model.extend({
kind: DS.attr('string'),
date: DS.attr('date'),
performer: DS.belongdTo('user'),
thread: DS.belongsTo('thread')
});
App.User = DS.Model.extend({
userName: DS.attr('string'),
displayName: DS.attr('string'),
profilePicUrl: DS.attr('string'),
activities: DS.hasMany('activity')
});
App.Thread.FIXTURES = [
{
id: '958173B3-EA1C-4E06-873A-038097A65E2F',
title: 'SE01',
url: '/sites/moon551/se01',
kind: 'Workspace',
lastActivityOn: '2014-03-01 10:46:31.4000000'
},
{
id: '9B45E3F0-13FD-48BE-83ED-F3C096C3BCC2',
title: 'To Do',
url: '/sites/moon551/se02/lists/todo',
kind: 'List',
lastActivityOn: '2014-02-28 11:46:31.4000000'
},
{
id: '6E6E4EE4-5568-49B3-B9E2-66CD60BA6CAC',
title: 'Design UX',
url: '/sites/moon551/se03/lists/todo/1',
kind: 'ListItem',
lastActivityOn: '2014-02-27 12:46:31.4000000'
}
];
App.Activity.FIXTURES = [
{
id: '37D7CBCD-0299-4203-8BF0-1B2DB676467F',
kind: 'Created',
date: '2014-03-01 10:30:31.4000000',
performer: 1073741823,
thread: '958173B3-EA1C-4E06-873A-038097A65E2F'
},
{
id: 'C378CD09-388C-403C-8558-3A1D6B5DCD97',
kind: 'Updated',
date: '2014-03-01 10:46:31.4000000',
performer: 1073741823,
thread: '958173B3-EA1C-4E06-873A-038097A65E2F'
},
{
id: 'C6B68036-7543-466F-85AF-141DB4874F75',
kind: 'Created',
date: '2014-02-28 11:30:31.4000000',
performer: 1073741823,
thread: '9B45E3F0-13FD-48BE-83ED-F3C096C3BCC2'
},
{
id: 'C378CD09-388C-403C-8558-3A1D6B5DCD97',
kind: 'Updated',
date: '2014-02-28 11:46:31.4000000',
performer: 1073741823,
thread: '9B45E3F0-13FD-48BE-83ED-F3C096C3BCC2'
},
{
id: 'C064010D-2603-4E28-9DE5-568212F1EFCA',
kind: 'Created',
date: '2014-02-27 12:30:31.4000000',
performer: 1073741823,
thread: '6E6E4EE4-5568-49B3-B9E2-66CD60BA6CAC'
},
{
id: '3C449D67-F231-4DB1-8D4D-AE0C39DB4E5D',
kind: 'Updated',
date: '2014-02-27 12:46:31.4000000',
performer: 1073741823,
thread: '6E6E4EE4-5568-49B3-B9E2-66CD60BA6CAC'
}
];
App.User.FIXTURES = [
{
id: 1073741823,
userName: 'Administrator',
displayName: 'System Account'
}
];
App.IndexController = Ember.ArrayController.extend();
App.IndexRoute = Ember.Route.extend({
model: function() {
return this.store.find('activity');
}
});
})(jQuery, Ember);
下面是一个实际的实物模型: