I'm trying to create a backbone app using Backbone.Layoutmanager.
I'm getting this rather unhelpful error
Uncaught TypeError: Object.keys called on non-object
I'm starting with an empty html file that I want to render an 'appChrome' layout into.
<!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>
Nothing to special there.
My app.js is pretty simple too,
/* 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();
});
Some of the magic starts to happen in the router
/*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");
}
});
})();
It that line in the initialize function thats throwing the error.
appChrome = new enrollmentProcessingApp.Views.AppChromeView();
Here's the AppChromeView View. Again very simple.
/*global enrollmentProcessingApp, Backbone, JST*/
enrollmentProcessingApp.Views = enrollmentProcessingApp.Views || {};
(function () {
'use strict';
enrollmentProcessingApp.Views.AppChromeView = Backbone.View.extend({
template: JST['app/scripts/templates/appChrome.ejs']
});
})();
As you can see I'm using JST. That template is super simple too.
<p>Hello World</p>
What the heck am I doing wrong?
This is an error caused by Underscore. Recently they've been breaking backward compatibilities without really caring about users... So error like this one start happening.
Solutions? - You can revert Underscore to 1.4.3 (or earlier) - You can use the latest LayoutManager from the
master
Branch or wait for release 0.9.3 (coming soon). (Related issue: https://github.com/tbranyen/backbone.layoutmanager/issues/383)