0
我有以下途徑:有麻煩我的模型建立
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
)}
感謝您抽出時間幫助。
非常感謝,我在這個問題像過去2-3個小時。我會盡快接受答案(我必須等待幾分鐘)。 –