0

我最近需要为我的所有模板使用 JST 文件,这样我就不会到处都有 html 模板的混乱。

我正在使用 grunt(使用 grunt-contrib-jst)构建 JST 文件,它会创建文件“build/templates.js”。

以下是那里的一个条目:

this["JST"] = this["JST"] || {};

this["JST"]["build/html/template-1.html"] = function(obj) {obj || (obj = {});var __t, __p = '', __e = _.escape;with (obj) {__p += '    <script type="text/template" id="template-1">\n        <span id="chat_title_1">' +((__t = ( title )) == null ? '' : __t) +'</span>\n        <span id="chat_symbol_1">▲&lt;/span>\n    </script>';}return __p};

我根据https://github.com/marionettejs/backbone.marionette/wiki/Using-jst-templates-with-marionette更新了我的骨干.marionette 渲染方法,它要求替换 Renderer.render 方法。请参阅下面的更改:

Marionette.Renderer = {
  render: function(template, data){

  if (!JST[template]) throw "Template '" + template + "' not found!";
  return JST[template](data);
  }
};

所以我认为有以下几点:

App.ChatBoxView = Backbone.Marionette.Layout.extend({
    template: "build/html/template-1.html",
...

页面加载,没有错误或任何东西,但页面上没有任何渲染,没有视图等。

有什么遗漏或做错了吗?

谢谢你。

4

1 回答 1

1

<script ....>解决了...我的模板html文件的开头和结尾仍然有。删除有效。

更新了“templates.js”中的条目示例:

this["JST"] = this["JST"] || {};

this["JST"]["build/html/template-1.html"] = function(obj) {obj || (obj = {});var __t, __p = '', __e = _.escape;with (obj) {__p += '<span id="chat_title_1">' +((__t = ( title )) == null ? '' : __t) +'</span>\n        <span id="chat_symbol_1">▲&lt;/span>';}return __p};
于 2014-06-18T13:12:07.537 回答