2015-12-07 31 views

回答

0

訣竅是在使用store.query將元素從DS高速緩存中拉出之後,將get()方法與'firstObject'一起使用。

這裏是我結束了做 - 如果任何人有這樣做,我很樂意聽到的更優雅的方式......

setupController: function(controller, model) { 
    var _this = this; 

    controller.set('model',model); 

    _this.store.findAll('club') 
    .then(function(results){ 
    controller.set('clubs', results); 
    return _this.store.query('club', {id:model.get('clubId')}); 
    }) 
    .then(function(result){ 
    controller.set('selectedClub', result.get('firstObject')); 
    }) 
    .catch(function(err){ 
    console.log("Error:",err); 
    }); 

},

1

您的解決方案將要求服務器的兩倍。檢查該解決方案(ES6語法)

setupController(controller, model) { 
    controller.set('model', model); 
    this.store.findAll('club').then(clubs => { 
    controller.set('clubs', clubs); 
    // i am not sure if the function is called filter, but it should be close enough 
    return clubs.filter(club => clubs.get('id') === model.get('clubId')).get('firstObject'); 
    }).then(selectedClub => controller.set('selectedClub', selectedClub)).catch(err => { 
    console.log("Error:", err); 
    }); 
} 
+0

謝謝 - 我已經想通,它將對查詢緩存沒有二次探底,但檢查你是對的,它做兩次存取服務器...會給這個今晚打擊。 –