Skip to content

Instantly share code, notes, and snippets.

@mplatts
Created Oct 30, 2012
Embed
What would you like to do?
Backbone Layout Manager Simple Example
<html>
<head>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js"></script>
<script src="https://raw.github.com/documentcloud/underscore/master/underscore.js"></script>
<script src="https://raw.github.com/documentcloud/backbone/master/backbone.js"></script>
<script src="https://raw.github.com/tbranyen/backbone.layoutmanager/master/backbone.layoutmanager.js"></script>
</head>
<body>
<div id="app"></div>
<script id="main-layout" type="layout">
<span class="one"></span>
</script>
<script type="text/template" id="one-template">
<div class="view">
<h1><%= name %></h1>
<span class="two-a"></span>
<span class="two-b"></span>
</div>
</script>
<script type="text/template" id="two-template">
<div class="view">
<h2><%= name %></h2>
</div>
</script>
<script>
var LevelOneView = Backbone.LayoutView.extend({
template: '#one-template',
serialize: {name: "Level One"}
});
var LevelTwoView = Backbone.LayoutView.extend({
template: '#two-template',
serialize: {name: "Level Two"}
});
var main = new Backbone.Layout({
template: "#main-layout",
views: {
".one": new LevelOneView({
views: {
".two-a": new LevelTwoView(),
".two-b": new LevelTwoView()
}
})
}
});
$("#app").empty().append(main.el);
main.render();
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment