2014-07-24 80 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