如何提供带有模板Ember 2的索引路径?

时间:2016-05-28 05:20:15

标签: javascript ember.js

我想创建一个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。怎么样?

http://jsbin.com/koyihapuze/edit?html,js,console,output

1 个答案:

答案 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开始