2013-01-24 104 views
1

这里NoTemplateError Backbone.Marrionette但节目模板是我的错误:错误味精

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方法中需要模板吗?

任何建议,非常感谢。

安德鲁

+0

(替他人)在我的情况下,错误发生了什么,因为被加载一个空的模板。当我在模板中添加HTML注释或空跨度时,错误消失了。 – Johannes

回答

2

通常木偶搜索该DOM内的模板,等于你在观看基准,所以你必须改变从Marionette.TemplateCache的loadTemplate这样的一个的ID:

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中我找不到它了,反正它对我来说工作得很好。

+0

工程就像一个魅力!谢谢!一旦你提到它,我就查阅了文档:https://github.com/marionettejs/backbone.marionette/blob/master/docs/marionette.templatecache.md – KingAndrew

+0

谢谢。帮助过我。 +1 –

0

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

  1. 当我已经改变了“未发现”模板的内容,它不是错误的消息改变。
  2. 当我改变它的文件名(并在导入语句中更新它) - 错误已修复,显示更新的内容。
  3. ...然后我改回了名字,一切都很好。

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

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

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

相关问题