我在使用通常对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 )...sex.ejs
<%= header %><sexform>Hello There</sexform>背景信息
正如预期的那样,header在读取器的时候是不可用的,这是通过grunt文件进行的,每次更改我的JST模板。我觉得我必须用错误的方式来实现JST。
但是,对我来说,这似乎是做每件事的正确方式。
当然,我尝试在sex.ejs中使用带有下划线的变量
所有这些代码都可以在这里看到:http://m.sexdiaries.co.uk/#wank NB: --我可以保证这对工作来说是安全的,并且不包含任何图片,尽管url实际上不是成人材料,它是一款教育应用。
发布于 2013-10-17 01:26:39
您可以这样定义视图的模板:
template: JST['app/www/js/templates/sex.ejs'],JST包含函数(这或多或少是使用JST样式预编译模板的全部要点):
this["JST"]["app/www/js/templates/sex.ejs"] = function (obj) {然后你就这么做:
var compiled = _.template(this.template(), this.data);
// function call ----------------------^^有两件事是不对的:
_.template来编译模板。this.template是一个编译好的模板函数,它期望被喂入this.data。修复非常简单:
var compiled = this.template(this.data);https://stackoverflow.com/questions/19415210
复制相似问题