ember.js - 给定数据模板名称的匹配模板名称是什么

标签 ember.js gruntjs grunt-ember-templates

我正在使用 grunt-ember-templates 预编译我的模板。正如预期的那样,该工具将我的模板放入 Ember.TEMPLATES 数组中。我正在微调 grunt-ember-templates 的配置。为此,我想知道 Ember.TEMPLATES 数组中的预期键是什么。假设我有这个模板:

<script type="text/x-handlebars" data-template-name="phones/index">
    ....
</script>

目前,我将此模板放在名为 app/templates/phones_index.hbs 的文件中,并且 grunt-ember-templates 正在将预编译的模板放入 >Ember.TEMPLATES["app/templates/phones_index"],但这是错误的。

data-template-name="phones/index" 的预期 key 是什么?

最佳答案

在您的示例中,Ember.TEMPLATES 中的键应为“电话/索引”。

您可以配置 grunt-ember-templates 来删除路径的第一部分,并保留 app/templates/ 之后的所有内容。假设您将模板放在文件 app/templates/phones/index.hbs 中,这将为您提供正确的 key 。使用此设置,app/templates/phones/index.hbs 的 key 文件将是 Ember.TEMPLATES['phones/index'] ,这与未编译的 <script> 相同标记为 data-template-name="phones/index" .

Gruntfile.js(与 this 项目中的 Gruntfile.js 相同):

ember_templates: {
  options: {
    templateName: function(sourceFile) {
      return sourceFile.replace(/app\/templates\//, '');
    }
  },
  'dependencies/compiled/templates.js': ["app/templates/**/*.hbs"]
},

关于ember.js - 给定数据模板名称的匹配模板名称是什么,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15887506/

相关文章:

templates - Uncaught Error : Template was precompiled with an older version of Handlebars

javascript - if 语句导致 TypeError : Cannont call unchain of undefined

ember.js - Ember - 理解逆关系

ember.js - 将 Ember.CollectionView 渲染到表中时设置 tbody 属性

javascript - Grunt 插件未安装在当前位置

javascript - Grunt Uglify - 如何创建用于调试的源映射?

javascript - 在没有 grunt 和 gulp 等构建工具的情况下使用 Javascript 框架?

ember.js - Emberjs 模板中的增量

javascript - 从 emberjs store.find 获取数据