Created
October 30, 2012 05:20
-
-
Save mplatts/3978446 to your computer and use it in GitHub Desktop.
Backbone Layout Manager Simple Example
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<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