我正在尝试使用 Backbone.Layoutmanager 创建一个主干应用程序。
我收到了这个相当无用的错误
Uncaught TypeError: Object.keys called on non-object
我从一个要在其中呈现“appChrome”布局的空 html 文件开始。
<!doctype html>
<!--[if lt IE 7]> <html class="no-js lt-ie9 lt-ie8 lt-ie7"> <![endif]-->
<!--[if IE 7]> <html class="no-js lt-ie9 lt-ie8"> <![endif]-->
<!--[if IE 8]> <html class="no-js lt-ie9"> <![endif]-->
<!--[if gt IE 8]><!--> <html class="no-js"> <!--<![endif]-->
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<title>Enrollment Processing</title>
<meta name="description" content="">
<meta name="viewport" content="width=device-width">
<link rel="stylesheet" href="styles/main.css">
<!-- build:js scripts/vendor/modernizr.js -->
<script src="bower_components/modernizr/modernizr.js"></script>
<!-- endbuild -->
</head>
<body>
<!-- build:js scripts/vendor.js -->
<script src="bower_components/jquery/jquery.js"></script>
<script src="bower_components/underscore/underscore.js"></script>
<script src="bower_components/backbone/backbone.js"></script>
<script src="bower_components/layoutmanager/backbone.layoutmanager.js"></script>
<!-- endbuild -->
<!-- build:js scripts/app.js -->
<script src="scripts/app.js"></script>
<script src="scripts/router.js"></script>
<script src="scripts/templates.js"></script>
<script src="scripts/views/appChrome.js"></script>
<!-- endbuild -->
</body>
</html>
那里没什么特别的。
我的 app.js 也很简单,
/* global enrollmentProcessingApp, $ */
window.enrollmentProcessingApp = {
Models: {},
Collections: {},
Views: {},
Routers: {},
init: function () {
'use strict';
Backbone.Layout.configure({
manage: true
});
var app = new enrollmentProcessingApp.Routers.AppRouter();
Backbone.history.start({pushState: true});
}
};
$(document).ready(function () {
'use strict';
enrollmentProcessingApp.init();
});
一些魔法开始在路由器中发生
/*global enrollmentProcessingApp, Backbone*/
enrollmentProcessingApp.Routers = enrollmentProcessingApp.Routers || {};
(function () {
'use strict';
enrollmentProcessingApp.Routers.AppRouter = Backbone.Router.extend({
routes: {
'' : 'default_route'
},
initialize: function(){
appChrome = new enrollmentProcessingApp.Views.AppChromeView();
},
default_route: function(){
console.log("default route called");
}
});
})();
它在引发错误的初始化函数中的那一行。
appChrome = new enrollmentProcessingApp.Views.AppChromeView();
这是 AppChromeView 视图。再次非常简单。
/*global enrollmentProcessingApp, Backbone, JST*/
enrollmentProcessingApp.Views = enrollmentProcessingApp.Views || {};
(function () {
'use strict';
enrollmentProcessingApp.Views.AppChromeView = Backbone.View.extend({
template: JST['app/scripts/templates/appChrome.ejs']
});
})();
如您所见,我正在使用 JST。那个模板也超级简单。
<p>Hello World</p>
我到底做错了什么?