我正在使用yeoman
,gruntjs
和handlebars.js
,但是我的模板不再加载,并且在 firebug 中出现以下错误:
TypeError: Handlebars.templates is undefined
var compiledTemplate = Handlebars.templates['cheatsheet.hbs'];
车把.JS
在我的package.json
,我得到:
"grunt-contrib-handlebars": "~0.5.9" // previously used ~0.5.8
Gruntjs 任务
任务:handlebars
我正在编译.hbs
文件.hbs.js
:
handlebars: {
compile: {
options: {
namespace: 'JST'
},
files: {
'<%= yeoman.app %>/scripts/cheatsheet.hbs.js':
[ '<%= yeoman.app %>/templates/{,*/}*.hbs'] ,
}
}
},
任务:watch
我在该watch
部分中添加了以下内容:
watch: {
// recompile handlebars' templates when they change
// @see: https://github.com/yeoman/yeoman/wiki/Handlebars-integration
handlebarsCompile: {
files: ['<%= yeoman.app %>/templates/{,*/}*.hbs'],
tasks: ['handlebars:compile']
},
handlebarsReload: {
files: ['<%= yeoman.app %>/scripts/{,*/}*.hbs.js'],
tasks: ['livereload']
},
任务:grunt server
和grunt build
我在这两个任务中添加了以下条目:
'handlebars:compile',
HTML 文件
我正在导入车把、模板和脚本来给它充气:
<script src="components/handlebars.js/dist/handlebars.runtime.js"></script>
<script src="scripts/cheatsheet.hbs.js"></script>
<script src="scripts/main.js"></script>
编译模板:cheatsheet.hbs.js
在最上面,我得到了这个:
this["JST"]["app/templates/cheatsheet.hbs"] = Handlebars.template(function (Handlebars,depth0,helpers,partials,data) {
模板充气机:main.js
为了膨胀我编译的模板,我正在使用这个:
var compiledTemplate = Handlebars.templates['cheatsheet.hbs'];
问题
那么这里的Handlebars.templates
数组是怎么回事?为什么没有创建?如何创建它?