将第二个模型添加到路由使得第一个未定义
adding second model to route makes first undefined
在我当前的 Ember 设置中,我检索了索引路由的商店。这很好用。
App.IndexRoute = Ember.Route.extend({
model: function(){
var store = this.store.find('index');
return store;
}
});
但是,我希望为同一路线创建一个自定义表单对象,因此按照 this SO answer 的建议尝试 return 像这样的索引路线的两个模型,但是,我现在得到错误
Error while processing route: index that is not defined ReferenceError: that is not defined
新代码
App.IndexRoute = Ember.Route.extend({
model: function(){
return Ember.RSVP.hash({
store: this.store.find('index'),
customform: App.CustomForm.create()
});
}
});
如何向这条路线添加第二个模型?
更新
索引模型有一个日期 属性,我用它来对索引模型中的项目进行排序
App.IndexController = Ember.ArrayController.extend({
sortProperties: ['date'],
sortAscending: false,
我最初是在 html
中用这个显示索引模型
{{#each item in arrangedContent}}
<li> {{some-component id=item.customid date=item.date data=item.junk}} </li>
{{/each}}
通过添加第二个模型,无论我是否使用商店创建记录,我都会收到此错误并且商店中的数据不会加载到 html
Error while processing route: index undefined is not a function TypeError: undefined is not a function
此外,我实际上不需要保留我尝试添加的第二个模型,因此我不想将其设为商店。在我链接到的 SO 答案中,添加了未保留的第二个模型。
看起来您应该使用商店来创建新的自定义表单记录:
App.IndexRoute = Ember.Route.extend({
model: function(){
return Ember.RSVP.hash({
store: this.store.find('index'),
customform: this.store.createRecord('customForm')
});
}
});
您将要通过您的商店创建自定义表单:
App.IndexRoute = Ember.Route.extend({
model: function() {
return Ember.RSVP.hash({
store: this.store.find('index'),
customForm: this.store.createRecord('customForm')
});
}
});
在我当前的 Ember 设置中,我检索了索引路由的商店。这很好用。
App.IndexRoute = Ember.Route.extend({
model: function(){
var store = this.store.find('index');
return store;
}
});
但是,我希望为同一路线创建一个自定义表单对象,因此按照 this SO answer 的建议尝试 return 像这样的索引路线的两个模型,但是,我现在得到错误
Error while processing route: index that is not defined ReferenceError: that is not defined
新代码
App.IndexRoute = Ember.Route.extend({
model: function(){
return Ember.RSVP.hash({
store: this.store.find('index'),
customform: App.CustomForm.create()
});
}
});
如何向这条路线添加第二个模型?
更新 索引模型有一个日期 属性,我用它来对索引模型中的项目进行排序
App.IndexController = Ember.ArrayController.extend({
sortProperties: ['date'],
sortAscending: false,
我最初是在 html
中用这个显示索引模型 {{#each item in arrangedContent}}
<li> {{some-component id=item.customid date=item.date data=item.junk}} </li>
{{/each}}
通过添加第二个模型,无论我是否使用商店创建记录,我都会收到此错误并且商店中的数据不会加载到 html
Error while processing route: index undefined is not a function TypeError: undefined is not a function
此外,我实际上不需要保留我尝试添加的第二个模型,因此我不想将其设为商店。在我链接到的 SO 答案中,添加了未保留的第二个模型。
看起来您应该使用商店来创建新的自定义表单记录:
App.IndexRoute = Ember.Route.extend({
model: function(){
return Ember.RSVP.hash({
store: this.store.find('index'),
customform: this.store.createRecord('customForm')
});
}
});
您将要通过您的商店创建自定义表单:
App.IndexRoute = Ember.Route.extend({
model: function() {
return Ember.RSVP.hash({
store: this.store.find('index'),
customForm: this.store.createRecord('customForm')
});
}
});