2013-01-14 48 views
0

这里是抛给我的控制台错误backbone.marionette与车把抛出异常试图加载我的模板

Uncaught TypeError: Object has no method 'chain' hbs.js:282 
getExternalDeps hbs.js:282 
(anonymous function) hbs.js:306 
xhr.onreadystatechange hbs.js:73 
Uncaught Error: Load timeout for modules: hbs!templates/reset_unnormalized2,hbs!templates/pages/login_unnormalized3,hbs!templates/reset,hbs!templates/pages/login 
http://requirejs.org/docs/errors.html#timeout require.js:160 

我使用的车把需要,插件,我甚至尝试添加“哈佛商学院”我需要垫片,但结果是一样的。

这里是我的提线木偶的视图代码:

define([ 
    "bootstrap", // bootstrap does not export anything, so no arg sent to our function 
    "marionette", 
    "session", "events", 
    "hbs!templates/pages/login" 
], function(Marionette, Session, Events, LoginTemplate){ 
    return Marionette.View.extend({ 
     template : { 
      type : "handlebars", 
      template : LoginTemplate 
     } 
    }); 
}); 

我不知道是怎么回事,每个搜索我已经拉升已经没有产生任何有用的结果。

发生了什么事?为什么发生这种情况?请帮忙。

回答

0

我想通了。

事实证明,我的问题与hbs插件无关,因为它与使用requirejs的handlebars和json2相关。

如上所述,第一个问题是通过将lodash库用underscore取出来解决的。我当时的印象是这两个是可以互换的,但显然是不是的情况。

然后我得到的错误"stringify" is not a function on the object null这导致我发现JSON没有在hbs里面定义。

我不得不回到我require.config({ shim:{} })并与JSON

现在我没有得到错误从hbs出口定义json2但我必须弄清楚,为什么我的观点并没有显示。

这里是我的配置代码,如果其他人有兴趣。

require.config({ 
    // paths to required javascript files 
    paths : { 
     bootstrap : "../assets/js/bootstrap.min", 
     jquery  : "../assets/js/jquery.min", 
     json2  : "../assets/js/json2", 
     underscore : "../assets/js/underscore.min", 
     backbone : "../assets/js/backbone.min", 
     marionette : "../assets/js/backbone.marionette.min", 
     hbs   : "../assets/js/hbs", 
     handlebars : "../assets/js/handlebars", 
     i18nprecompile : "../assets/js/hbs/i18nprecompile" 
    }, 

    // "shim" will allows us to load in deps synchronously so that we do not 
    // run into a situation where dependencies are not available 
    shim : { 
     json2  : { exports : "JSON" }, 
     jquery  : { exports : "jQuery" }, 
     underscore : { exports : "_" }, 
     backbone : { 
      deps : ["jquery", "underscore", "json2"], 
      exports : "Backbone" 
     }, 
     marionette : { 
      deps : ["jquery", "underscore", "json2", "backbone"], 
      exports : "Marionette" 
     }, 
     hbs : { 
      deps : ["jquery", "underscore", "json2", "i18nprecompile", "handlebars"], 
      exports : "hbs" 
     }, 
     bootstrap : { deps : ["jquery"] } 
    } 
}); 
3

可能是你的参数定义错误吗?如果一个值没有定义任何东西(比如引导程序),那就让它最后一个。现在你的木偶arg包含未定义的bootstrap值,Session现在持有木偶等。

define([ 
    "marionette", 
    "session", "events", 
    "hbs!templates/pages/login", 
    "bootstrap", // bootstrap does not export anything, so no arg sent to our function 
], function(Marionette, Session, Events, LoginTemplate){ 
    return Marionette.View.extend({ 
     template : { 
      type : "handlebars", 
      template : LoginTemplate 
     } 
    }); 
}); 
+0

指出。从现在开始,我会把这样的任何一个转移到列表的末尾。谢谢! – rkstar