2014-07-24 35 views
1

我试图改变我的意见,当模型属性发生变化 林不知道我是否在正确的轨道上,但在这里。在子路径中过滤RecordArray以返回RecordArray?

我有叫午餐父资源,其路径看起来像这样:

model: function(params){ 
    return this.store.filter('lunch', params, this.funcAll); 
} 

,我有一个孩子的路线“服务”,其路径看起来像这样:

model: function(params){ 
    return this.modelFor('lunches').filterProperty('isServed', true); 
    // as opposed to this.store.filter('lunch', this.funcFilter()}) 
} 

当我在子路径中使用过滤器,我能够做到这一点(我认为是因为一个过滤器返回一个RecordArray),但这不适用于我,另一个原因。无论如何,我可以让我的子路线返回一个RecordArray,它是原始模型的一个子集?

回答

0

filter作品集。

App.ColorsRoute = Ember.Route.extend({ 
    model: function() { 
    this.store.find('color'); 
    return this.store.filter('color',function(){ 
     return true; 
    }); 
    } 
}); 

App.ColorRoute = Ember.Route.extend({ 
    model: function(params) { 
    return this.store.find('color', params.id); 
    }, 
    setupController: function(controller, model){ 
    this._super(controller, model); 

    var cMod = this.modelFor('colors'), 
    subItems = cMod.filter(function(item){ 
     return item.get('color').indexOf('e')>=0; 

    }); 
    console.log(subItems.get('length')); 
    } 
}); 

http://emberjs.jsbin.com/OxIDiVU/858/edit

+0

非常感谢主销!我发现我犯的错误很多。但是,多亏了你,我已经明白了这一点。 – user3874510