我想创建一个 ember 应用程序,如下所示:
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
未定义(在解析器内),因此您
修复代码如
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 或 templateName 定义 ApplicationView 并解决解析器错误
附注最好使用 ember-cli 从 Ember 开始
关于javascript - 如何使用模板 Ember 2 提供索引路由?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37495492/