【发布时间】:2013-02-08 23:30:25
【问题描述】:
我只是想知道是否有人在骨干项目中使用过这个插件。
我不想将所有脚本模板标签都放在一个索引文件中,而是希望将模板与需要它们的视图放在同一目录中。
所以我希望我可以使用节点选项来要求本地模板并渲染到它,然后附加到我的索引文件上的#id(我将在最后整理)。
所以基本上我有我的车把模板 (template.hbs) 及其编译的 js (template.js) 以及我的主干视图 index.coffee。
public
|_ coffee
|_views
|_card
|_list
index.coffee
template.hbs
template.js
作为参考,我的 grunt 文件如下所示:
handlebars: {
compile: {
options: {
namespace: 'MyApp.Templates',
node: true
},
files: {
"public/coffee/views/card/list/template.js": "public/coffee/views/card/list/template.hbs"
}
}
},
在我的主干视图 (index.coffee) 中,我希望像这样需要车把模板:
class CardList extends Backbone.View
template: require('./template')
…
do some other shiz
…
render: =>
template = Handlebars.compile($(this.template).html())
html = template
model: this.model
$(this.el).html(html)
渲染这个是在检查器中吐出这个错误:
Uncaught [object Object]
> template = handlebars.compile($(this.template).html());
我显然不知道自己在做什么,所以我希望有人能说明我如何正确使用这个插件。
我正在使用 grunt-contrib-handlebars v0.3.5
感谢任何帮助。
谢谢
【问题讨论】:
标签: backbone.js handlebars.js gruntjs