1

这是我的错误:

Uncaught NoTemplateError: Could not find template: '<!-- HTML Template --> 
<div id="start_div">

<h2>Choose your path to ... // the rest of the template

它告诉我没有模板,但是它输出了它说找不到的模板。

这是我的代码:

require(["jquery", "marionette", "views/StartView" ],
function($, marionette, StartView) {

  var SCApp = new marionette.Application();

  SCApp.addRegions({
      mainRegion: "#center_court"
  });
  var startView = new StartView();
  SCApp.mainRegion.show(startView);
  SCApp.start();

}

这是 StartView.js

define(["jquery", "marionette", "text!templates/startDiv.html"],

function($, marionette, template){

    var StartView = marionette.ItemView.extend({
       //template: "#start_div"
        template: template
    });

    // Returns the View class
    return StartView;

});

谁能看到我做错了什么?我是否需要在 require 方法中进行模板化?

任何建议都非常感谢。

安德鲁

4

2 回答 2

2

通常 Marionette 在 DOM 中搜索一个模板,其 ID 等于您在视图中引用的 ID,因此您必须以这种方式从 Marionette.TemplateCache 更改 loadTemplate:

Backbone.Marionette.TemplateCache.prototype.loadTemplate = function(templateId) {

    var template = templateId;

    if (!template || template.length === 0){
        var msg = "Could not find template: '" + templateId + "'";
        var err = new Error(msg);
        err.name = "NoTemplateError";
        throw err;
    }

    return template;
};

我实际上不记得我在哪里找到了这个功能,我在 Marionette 的 Wiki 中再也找不到它了,无论如何它对我来说很好用。

于 2013-01-24T11:12:32.000 回答
0

我昨天遇到了同样的问题,发现了下一个有趣的事实:

  1. 当我更改了“未找到”模板的内容时,错误消息中没有更改。
  2. 当我更改它的文件名(并在导入语句中更新它)时——错误得到修复,更新的内容被显示。
  3. ...然后我又改了名字,一切都很好。

看起来像缓存的一些错误。

更新:在这里我找到了深入的分析和解决方案:

http://blog.icanmakethiswork.io/2014/03/caching-and-cache-busting-with-requirejs.html

于 2015-08-26T08:22:29.927 回答