由grunt-contrib-jst -undefined错误编译时,下划线jst的正确模式

时间:2015-06-17 17:26:24

标签: backbone.js underscore.js underscore.js-templating

我设法将我收到的错误消息缩小到一行。

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>

到目前为止,我还没有找到正确的模式来使用带变量的编译模板(如果删除属性变量,它可以正常工作)。

0 个答案:

没有答案