【问题标题】:Require.js JST filesRequire.js JST 文件
【发布时间】:2013-05-17 13:58:51
【问题描述】:

这是我的示例 JST 文件

(function() {
  var _ref;

  if ((_ref = window.JST) == null) {
    window.JST = {};
  }

 window.JST['test'] = function(context) {
   return (function() {
   var $o;

  $o = [];
  $o.push("<h1>yayyyyyyaa</h1>");
  return $o.join("\n");
 }).call(context);
};

}).call(this);

我在主干应用程序中使用 require.js,例如

define ['backbone', 'marionette', 'text!javascripts/backbone/templates/test.jst'],    
(Backbone, Marionette, template) ->

   class Test extends Backbone.Marionette.ItemView
       template: JST[template]

当我加载应用程序时,我得到:

ReferenceError: JST is not defined

为什么哦为什么!

谢谢!

【问题讨论】:

    标签: backbone.js requirejs marionette


    【解决方案1】:

    您的代码的问题是您在“模板”变量中获取函数的文本。您仍然需要eval 该文本才能在窗口上创建一个实际的 JST 实例。

    整体的问题是你在滥用文本!插件,你真正需要做的是使用 requireJs 的模块,而不是把你的变量挂在窗口上。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-03-21
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多