私は、通常は understand.js では問題にならない変数の使用に問題がありますが、JST と underscore.js を組み合わせると、どうやら苦労しているようです。
var something= SD.defaultView.extend({
el: 'page',
template: JST['app/www/js/templates/sex.ejs'],
data: {
header: 'some information!!!',
image: '/img/path.jpg'
},
render: function () {
var compiled = _.template(this.template(), this.data); //I pass in the complied JST template
this.$el.html(compiled);
}
});
レンダリングされた JST ファイル
this["JST"]["app/www/js/templates/sex.ejs"] = function (obj) {
obj || (obj = {});
var __t, __p = '', __e = _.escape;
with (obj) {
__p += ((__t = ( header )) == null ? '' : __t) + '<sexform>Hello There</sexform>';
}
return __p
};
エラー
ReferenceError: header is not defined - templates.js (line 21)
...obj = {});var __t, __p = '', __e = _.escape;with (obj) {__p +=((__t = ( header )...
セックス.ejs
<%= header %><sexform>Hello There</sexform>
背景情報
予想どおり、header
リーダーの時点では利用できません。これは、JST テンプレートが変更されるたびに grunt ファイルを介して発生しています。JST を間違った方法で実装しなければならないと感じています。
しかし、私にはこれがすべてを行う正しい方法のように思えます。
もちろん、sex.ejs 内でアンダースコア付きの変数を使用しようとしています。
このコードはすべてここで見ることができます: http://m.sexdiaries.co.uk/#wank 注: URL と同じように誤解を招く可能性がありますが、実際にはそうではありません。アダルト素材、教育アプリです。