Javascript Ember.js:未定义模板类型?
主路由器正在将用户正确路由到下面的App.IndexRoute:Javascript Ember.js:未定义模板类型?,javascript,ember.js,url-routing,Javascript,Ember.js,Url Routing,主路由器正在将用户正确路由到下面的App.IndexRoute: App.IndexRoute = Ember.Route.extend({ model: function() { return App.Contact.find(); }, init: function() {console.log('were in the indexroute! ive been created.')}, controller: 'index', setupController:
App.IndexRoute = Ember.Route.extend({
model: function() {
return App.Contact.find();
},
init: function() {console.log('were in the indexroute! ive been created.')},
controller: 'index',
setupController: function(controller) {
controller.set('content', App.Contact.find());
console.log('the IndexController is set up, with the model equal to ' + controller.get('content') + '.');
},
renderTemplate: function() {
this._super();
this.render('contacts', {
outlet: 'sidebar',
into:'index',
controller: 'contacts'
});
this.render('map', {
into: 'index',
outlet: 'map', //cannot connect outlet yet, acc. GitHub ember-data gist #1838
controller: 'map'
});
}
});
但是索引页面拒绝加载任何动态的、由把手定义的内容。从renderTemplate
函数中删除this.\u super()
会产生类型错误,未定义“connectOutlet”。我在索引页面的把手模板中得到了注释(当然是隐藏的),所以我知道它们加载正确
有人能发现路线定义的任何问题吗?如果没有,我将不得不进一步研究。任何建议都将不胜感激
注:Ember、ruby、rails等都是最新的。Chrome控制台调试器提供:
DEBUG: Ember.VERSION : 1.0.0-rc.1 ember.js:348
DEBUG: Handlebars.VERSION : 1.0.0-rc.3 ember.js:348
DEBUG: jQuery.VERSION : 1.9.1
默认情况下,renderTemplate只调用this.render(),在本例中,它设置了默认索引模板,其他渲染器正试图将其他模板插入其中。这就是删除super会导致错误的原因。如果这个.render()使代码更清晰,则可以用它替换超级调用。你也能展示你的模板吗?是否存在与模板关联的自定义视图?这可能是因为您没有从
init
方法内部调用This.\u super()
。尝试添加它,或者完全删除init
覆盖。实际上,Route
没有init
,它直接继承自Ember.Object
,它只是CoreObject
,它有一个空的init
。因此,这是少数不必在init
中调用\u super()
的情况之一。但是,是的,当您重写init
时,养成不调用this.\u super()
的习惯不是一个好主意。