Last active
December 14, 2015 01:29
-
-
Save chiller/5006289 to your computer and use it in GitHub Desktop.
Cheatsheet: skeleton for a small backbone exampleapp
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
class NestedCommentView extends Backbone.View | |
tagname: "div" | |
initialize: => | |
@model.bind 'change', @render | |
@model.bind 'destroy', @unrender | |
#bind this to a dom event | |
#events: | |
# "click .deletecomment": "deleteComment" | |
deleteComment: => | |
@model.destroy() | |
render: => | |
$(@el).html "<p>Test #{@model.get 'name'}</p>" | |
@ | |
unrender: => | |
$(@el).remove() | |
@ | |
class TestModel extends Backbone.Model | |
render: => | |
myview = new NestedCommentView model: @ | |
$("body").append myview.render().el | |
class CommentList extends Backbone.Collection | |
model: TestModel | |
initialize: => | |
@bind 'add', (item) -> item.render() | |
$ -> | |
window.commentCollection = new CommentList | |
window.commentCollection.add([ | |
new TestModel name:"alma", | |
new TestModel name:"korte", | |
new TestModel name:"birs", | |
]) | |
window.commentCollection.models[0].set("name","banana") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment