我正在尝试显示一个列表,它是列表列表的并集。
我有两个hasMany关系将电影链接到一个库
+---------+ hasMany +---------+ hasMany +-------+
| Library | ---------> | Storage | ---------> | Movie |
+---------+ +---------+ +-------+
Javascript:
App.Library = DS.Model.extend({
name : DS.attr(),
storages : DS.hasMany('storage', {async:true})
});
App.Storage = DS.Model.extend({
hostname : DS.attr(),
login : DS.attr(),
password : DS.attr(),
name : DS.attr(),
movies: DS.hasMany('movie', {async:true})
});
App.Movie = DS.Model.extend({
name: DS.attr()
duration : DS.attr()
});
该库已加载到我的AppController中:
App.ApplicationController = Ember.Controller.extend({
data: function() {
return this.get('store').find('library', 1);
}.property()
});
我要做的是显示我的图书馆所有电影的列表,按名称排序。我尝试了类似的东西,这是行不通的:
App.LibraryController = Ember.ArrayController.extend({
needs: ['application'],
sortProperties : [ 'name' ],
sortAscending : true,
model: function() {
var storages = this.get('controllers.application.data.storages');
if (storages) {
return storages.mapBy('cpls').reduce(function(accum, items) {
return accum.pushObjects(items);
}, Ember.ArrayController.create({}));
}
else {
return [];
}
}.property('controllers.application.data.storages.@each')
});
但这种方法有几个问题:
controllers.application.data.storages.@each.movies.@each
,但EmberJS不支持在@each之后添加选择器(请参阅computed properties and aggregate data with @each末尾的注释)我需要一些指示,有人知道如何正确解决这个问题吗?
编辑:
我发现这个问题与我的问题An implementation of a merged array in Ember.js that combines items from multiple source arrays
有关