バックボーン プロジェクトでこのプラグインを使用した経験のある人がいるかどうか疑問に思っています。
すべてのスクリプト テンプレート タグを 1 つのインデックス ファイルに格納する代わりに、テンプレートを必要とするビューと同じディレクトリに配置したいと考えました。
したがって、ノード オプションを使用してローカル テンプレートを要求し、それにレンダリングしてから、インデックス ファイルの #id に追加できることを期待していました (後で整理します)。
したがって、基本的には、バックボーン ビューである index.coffee と一緒に、ハンドルバー テンプレート (template.hbs) とそのコンパイル済み js (template.js) があります。
public
|_ coffee
|_views
|_card
|_list
index.coffee
template.hbs
template.js
参考までに、私のうなり声ファイルは次のようになります。
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 を使用しています
どんな助けでも大歓迎です。
ありがとう