2013-01-24 62 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

相關問題