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