javascript - 如何使用模板 Ember 2 提供索引路由?

标签 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) 在您的代码中 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/

相关文章:

javascript - 将多个 native 事件映射到 Ember.js 中的语义应用程序事件?

javascript - 如何让 jQuery 在上传之前选择文件时过滤文件类型?

javascript - 获取字符串形式的对象名称

javascript - 是否可以在 Handlebars 模板中嵌套 if/else 语句?

javascript - ember.js 是否关心它是在页面顶部还是底部调用

javascript - 无法通过 ember 安装 bourbon

javascript - 找不到 Ember 组件

ember.js - 如何将项目的CSS文件编译成一个文件

javascript - 如何拥有默认参数并根据此函数的需要覆盖这些参数?

javascript - 将 model.obj 添加到 Three.MESH