【发布时间】:2016-08-07 05:13:26
【问题描述】:
我现在有一个非常简单的设置。我有一个有名字和作者的图书模型。我正在尝试创建一个简单的表单来创建一本新书。对于作者,我使用 power select 从作者模型中加载作者。设置的表单如下所示:
<form {{action "save" on="submit"}}>
{{input value=model.title placeholder="Title"}}<br>
{{#power-select class="select"
selected=model.author
options=authors
onchange=(action (mut model.author)) as |author|}}
{{author.name}}
{{/power-select}}
<input type="submit" value="Save">
</form>
但是,我在设置路线以使其正常工作时遇到了麻烦。到目前为止,没有作者出现在选择中,即使有作者存储在我的数据库中。我的路线如下所示:
import Ember from 'ember';
export default Ember.Route.extend({
model() {
return this.store.createRecord('book');
},
actions: {
save() {
this.modelFor(this.routeName).save();
}
},
store: Ember.inject.service(),
authors: Ember.computed({
get() {
return this.get('store').findAll('author');
}
}).readOnly()
});
首先,我应该如何在书籍/新路线的路线中正确加载作者模型中的数据?其次,我应该在路线上这样做吗?从我读过的内容和人们告诉我的内容来看,加载模型数据应该在路线中完成。
【问题讨论】: