Marionette 应用程序未启动且没有错误!什么地方出了错?

Marionette App not starting and there's no error! What went wrong?

我正在尝试 David Sulc 对 Marionette.js (Backbone.js) 的温和介绍 在几乎是第一个练习中,我遇到了一个奇怪的问题。当我 运行 chrome 或 firefox 中的代码时,我在控制台中没有看到任何错误,但显然应用程序尚未启动(否则,marionette 呈现的文本应该是可见的)。同样,"console.log" 命令在控制台 window 中没有显示任何响应。控制台绝对是空白的。没有错误,没有警告。请帮忙。

这是代码。请让我知道我到底做错了什么。

<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8" >
    <title>Marionette Test Contacts</title>
    <link rel="stylesheet" href="assets/css/bootstrap.css" />
    <link rel="stylesheet" href="assets/css/application.css" />

</head>

<body>
    <div class="navbar navbar-inverse navbar-fixed-top">
        <div class="navbar-inner">
            <div class="container">
                <span class="brand">Contact manager</span>
            </div>
        </div>
    </div>

    <div id="main-region" class="container">
        <p>Content to hide when app starts.</p>
    </div>

    <script type="text/template" id="static-template">
        <p>This is generated by Marionette app.</p>
    </script>       

    <script src="http://code.jquery.com/jquery-1.10.2.js"></script>
    <script src="https://raw.github.com/douglascrockford/JSON-js/master/json2.js"></script>
    <script src="http://underscorejs.org/underscore.js"></script>
    <script src="http://backbonejs.org/backbone.js"></script>
    <script src="http://marionettejs.com/downloads/backbone.marionette.js"></script>

    <script type="text/javascript">
        var ContactManager=new Marionette.Application();
        ContactManager.on("initialize:after", function(){
            console.log("ContactManager has started!");
            var staticView=new ContactManager.StaticView();
            ContactManager.mainRegion.show(staticView);

        });
        ContactManager.start();
    </script>    
</body>
</html>

我认为您混淆了 Marionette 的两个不同版本的语法。
如果您使用 start(),请尝试:

ContactManager.on("start", function(){}); 

根据文档,事件是:

  • "before:start" / onBeforeStart: fired just before the Application starts and before the initializers are executed.
  • "start" / onStart: fires after the Application has started and after the initializers have been executed.

https://github.com/marionettejs/backbone.marionette/blob/master/docs/marionette.application.md