我设法将我收到的错误消息缩小到一行。
ReferenceError: property is not defined
((__t = ( property )) == null ? '' : __t) +
视图控制器如下(为简洁起见而简化)
workSpace.viewMain = Backbone.View.extend({
// WORKS
// template: _.template($("#desk-view-main").html()),
// DOESNT WORK
template: _.template(window.JST["public/js/app/templates/desk-view-main.html"]()),
// DOESNT WORK
// template: _.template(window.JST["public/js/app/templates/desk-view-main.html"](), {"key": "value"}),
el: '#pw-main',
initialize: function() {
this.render();
},
render: function(a) {
var dictionary = {"key": "value"}
var html = that.template(dictionary);
$(that.el).append(html);
}
});
编译后的文件如下所示
this["JST"] = this["JST"] || {};
this["JST"]["public/js/app/templates/desk-view-main.html"] = function(obj) {
obj || (obj = {});
var __t, __p = '', __e = _.escape;
with (obj) {
__p += ' <nav id="tweak"></nav>\n <div class="desk">\n <h3>Workspace:</h3>\n <strong> ' +
((__t = ( property )) == null ? '' : __t) +
'</strong>\n\n <h3>end Workspace:</h3>\n </div>\n</div>\n';
}
return __p
};
来自以下的public / js / app / templates / desk-view-main.html
<div class="desk">
<h3>Workspace:</h3>
<span> <%= property %></span>
<h3>end Workspace:</h3>
</div>
到目前为止,我还没有找到正确的模式来使用带变量的编译模板(如果删除属性变量,它可以正常工作)。