0
爲什麼將setupController
添加到路由時,model
掛鉤返回的model
值爲null
?當有setupController時,從模型掛鉤返回的模型值爲空
http://jsbin.com/pahuno/1/edit
我知道我可以解決它通過設置在setupController
的model
價值,但我想知道這是什麼問題
爲什麼將setupController
添加到路由時,model
掛鉤返回的model
值爲null
?當有setupController時,從模型掛鉤返回的模型值爲空
http://jsbin.com/pahuno/1/edit
我知道我可以解決它通過設置在setupController
的model
價值,但我想知道這是什麼問題
當您使用掛鉤,這樣的如setupController
或renderTemplate
,您正在阻止Ember處理默認情況。對默認方法的調用:
App.IndexRoute = Ember.Route.extend({
model: function() {
return ['red', 'yellow', 'blue'];
},
setupController: function(controller, model) {
this._super(controller, model);
}
});
從灰燼源評論:
這種方法被稱爲與控制器當前路線和 由
model
鉤提供的 模型。默認情況下,
setupController
掛鉤將model
屬性 控制器設置爲model
。如果你在你的路由中實現了setupController
掛鉤,它將會阻止這個默認行爲 。如果你想實現你的setupController
功能時保留該行爲 ,請確保調用_super
: