Created
April 5, 2012 16:39
-
-
Save gsmaverick/2312413 to your computer and use it in GitHub Desktop.
Handling tree-like layouts in Backbone
This file contains 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
var TreeItemView = Backbone.View.extend({ | |
tagName: 'div', | |
className: 'tree-item', | |
render: function() { | |
var self = this; | |
// Some function that retrieves an array of children for this model | |
var children = TreeCollection.children(this.model.get('id')); | |
// Render this tree item | |
$(this.el).html(this.template({ this.model.toJSON(); })); | |
// Render all the children of this tree item | |
_.each(children, function(child) { | |
var view = new TreeItemView({ model: child }); | |
$(self.el).append(view.render().el); | |
}); | |
return this; | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment