基本上我有项目模型和资源模型。项目有许多资源,资源有许多项目(多对多关系)。所以我想查看全部或过滤不属于我的项目的资源。像这样:
this.store.filter('resource', function(resource){
resource.get('projects') != this.get('project')
})
应该是这样的。我不知道什么是正确的方法。我只想获取那些没有this.get('project')或特定项目的资源。
您可以使用
组合peekAll
和rejectBy
。
var resourcesThatDoNotBelongToMyProject = this.get('store').peekAll('resources').rejectBy('projects', this.get('project'));
请注意,rejectBy
的反面是findBy
它将返回所有不属于我的project
的活动资源
resourcesThatDoNotBelongToMyProject: Ember.computed('resources',function(){
var _self = this;
return this.get('resources').filter(function(resource){
let not_present=true;
if(resource.get('projects') != undefined) {
resource.get('projects').forEach(function (project) {
if (project.id == _self.get('model').id) {
not_present = false;
}
});
}
if(not_present == true) {
return resource.get("active") == true
}
});
}),