![](/img/trans.png)
[英]Ember how do I know when a route template is finished loading and fire a callback?
[英]How do I supply an index route with a template Ember 2?
我想創建一個余燼應用程序,如下所示:
var app = Ember.Application.create({
rootElement: document.getElementById('root'),
name: 'my-application',
IndexRoute: Ember.Route.extend({
model: function() {
console.log('model');
},
afterModel: function(model, transition) {
},
template: Ember.Handlebars.compile('<div id="test"></div>'),
}),
locationType: 'hash',
});
問題是我沒有在DOM中獲得測試div。 怎么會?
1)在您的代碼中this.namespace.TEMPLATES
是未定義的(在resolver內部),因此您可以修復如下代碼
resolveTemplate: function(parsedName) {
var templatePath = parsedName.fullNameWithoutType.replace('.', '/');
var template = this.namespace.TEMPLATES && this.namespace.TEMPLATES[templatePath];
if (!template) {
template = this._super(parsedName);
}
return template;
},
在應用程序容器內找到新的div.ember-view元素之后
2)template不是路由的屬性(如您的代碼所示),您可以在路由器中使用template或templateName定義ApplicationView並解決解析器錯誤
PS最好使用ember-cli從Ember開始
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.