我正在尝试 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/