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);
下面是一個實際的實物模型: