2016-08-08 3 views
0

RSVP 해시를 사용하여 내 경로 중 하나에서 두 모델의 데이터를 가져온 다음 해당 결과를 내 컨트롤러에서 결합하여 힘의 정렬을위한 선택. 그러나 무언가가 작동하지 않는 것 같습니다.ember - 두 모델의 데이터를 하나의 결과로 결합하여 출력 정렬

내 경로는 다음과 같습니다

내 템플릿은 다음과 같습니다
import Ember from 'ember'; 

export default Ember.Route.extend({ 
    model() { 
     return Ember.RSVP.hash({ 
      newBook : this.store.createRecord('book'), 
      authors : this.store.findAll('author'), 
      publishing_houses : this.store.findAll('publishing-house')  
     }); 
    }, 

    setupController(controller, model) { 
     this._super(...arguments); 
     Ember.set(controller, 'authors', model.authors); 
     Ember.set(controller, 'publishing_houses', model.publishing_houses); 
    }, 

    actions: { 
     save() { 
      this.modelFor(this.routeName).get('newBook').save(); 
     } 
    }  
}); 

:

<form {{action "save" on="submit"}}> 
    {{input value=model.newBook.title placeholder="Title"}}<br> 
    {{input value=model.newBook.price placeholder="Price"}}<br> 

    {{#power-select class="select" 
     selected=model.newBook.author 
     options=model.authors 
     onchange=(action (mut model.newBook.author)) as |author|}} 
     {{author.name}} 
    {{/power-select}} 

    {{#power-select class="select" 
     selected=model.newBook.publisher 
     options=model.publishers 
     onchange=(action (mut model.newBook.publisher)) as |publisher|}} 
     {{publisher.name}} 
    {{/power-select}} 

    <input type="submit" value="Save"> 
</form> 

나는 문제가 다음과 같습니다 생각 내 컨트롤러 :

import Ember from 'ember'; 

export default Ember.Controller.extend({ 
    publishers: function() { 
     var authors = this.get("authors"); 
     var publishingHouses = this.get("publishing_houses"); 
     return authors.concat(publishingHouses); 
    } 
}); 

나는 컨트롤러를 사용하는 방법을 아직도 고민 중이다. 컨트롤러에서 모델 데이터에 올바르게 액세스하고 있습니까? 또한 템플릿에서 사용할 속성을 만드는 적절한 방법입니까?

답변

0

setupController 훅에서는 슈퍼 함수 호출을 통해 기본적으로 설정되므로 authorspublishing_houses을 명시 적으로 설정할 필요가 없습니다. 컨트롤러에서

, 당신은 get 기능이없는 직접 액세스해야 newBook

이 경로에서 RSVP 수익 모델에 액세스하려면 this.get("model.authors") 같은 및 기타 속성 publishing_houses에 대해 동일한 방법으로 접근 시도 할 수 있습니다.

은`연결 및 기타 물건에 대한 this.modelFor (this.routeName) .newBook.save()

당신은 당신의 필요 스위트 수

reducehttp://emberjs.com/api/classes/Ember.Enumerable.html를 참조하십시오.

관련 문제