我想创建一个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。怎么样?
答案 0 :(得分:2)
this.namespace.TEMPLATES
中的1)未定义(在解析器内),所以你 修复代码,如
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)模板不是路由属性(如代码中所示),您可以在路由器中使用模板或templateName定义ApplicationView并解决解析器错误
P.S。最好从使用ember-cli的Ember开始