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

标签 javascript jquery html backbone.js marionette

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

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

<!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

关于javascript - Marionette 应用程序未启动,并且没有错误!什么地方出了错?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31180814/

相关文章:

javascript - jQuery Ajax 请求在未发送的情况下被取消

javascript - 从主题演讲中提取PresentationNotes

javascript - 在 DOM 就绪事件上加载大量脚本片段的模式,而 IE 8 不会弹出脚本超时警告

php - 在 PHP 中使用单引号(转义)

jquery - 将 div 放置在通知中心正下方

javascript - CasperJS 测试覆盖率

javascript - 如何获取google搜索结果的间接链接

jquery - 如何在嵌套元素上应用 css

html - CSS3 动画全屏

javascript - 渐进式 Web 应用程序 - 离线时在多个缓存页面之间导航