2014-02-17 43 views
2

筛选模型是正常的性能是相当简单的,我得到它的工作:筛选模型,通过它的一个关系

filteredModel: function() { 
    return this.get("model").filterBy("property", filter); 
}.property("model") 

但现在我的问题,我怎么可以用的hasMany关系筛选模式? 我的模特儿(有视频)有'标签',我想要的只是显示'绘制'标签的视频。

我怎么能做到这一点?

回答

2

包括在你ArrayController如下:

filtered: function() { 
    return this.get('content').filter(function(item, index, enumerable){ 
    var result = false; 
    item.get('tags').forEach(function(tag) { 
     if (tag.get('name') === 'drawn') result = true; 
    }); 
    return result; 
    }); 
}.property('[email protected]') 
+0

没错,但问题是,标签在模型中的'hasMany'关系。那么我怎么能通过一个关系在一个计算的过程中过滤呢? 'this.get('model')。filterBy('tags.name','drawn');'或者类似的技巧似乎不起作用。 – Markus

+0

查看我的答案更新 – chopper

相关问题