【发布时间】:2013-12-20 00:23:10
【问题描述】:
我有以下路线:
this.resource('categories', function() {
this.route('add');
this.resource('category', {path: ':category_id'}, function() {
this.route('edit', {path: "/edit"});
this.resource('products', function(){
this.route('add');
this.resource('product', {path: ':product_id'});
});
});
});
除编辑路线外,一切正常。由于某些奇怪的原因,我的模型没有被初始化。
App.CategoryRoute = Ember.Route.extend({
model: function (params) {
console.log(this.store.getById('category', params.category_id)); // Returns what I want
return this.store.getById('category', params.category_id);
},
//other stuff
});
经过几次尝试/错误,我发现我的 CategoryEditRoute 覆盖了我的模型。我不是 100% 确定这个说法,但它看起来像。如果我尝试在这条路线上设置我的模型,我将无法访问我的参数...没有我的参数我不知道要加载什么模型!!!
App.CategoryEditRoute = Ember.Route.extend({
model: function (params) {
console.log(params); // Result in: Object {}
return this.store.getById('category', params.category_id); // Undefined
},
// Other stuff
)}
感谢您抽出宝贵时间提供帮助。
【问题讨论】:
标签: ember.js ember-data