-
-
Save 798bin/7657198 to your computer and use it in GitHub Desktop.
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
| <!DOCTYPE html> | |
| <html> | |
| <head> | |
| <meta charset=utf-8 /> | |
| <script src="http://zeptojs.com/zepto.min.js"></script> | |
| <script src="http://documentcloud.github.io/underscore/underscore-min.js"></script> | |
| <script src="http://documentcloud.github.io/backbone/backbone-min.js"></script> | |
| <title>JS Bin</title> | |
| </head> | |
| <body> | |
| <div id="todo_box"> | |
| <h1>todo_box</h1> | |
| </div> | |
| <button id="change">Change</button> | |
| </body> | |
| </html> |
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
| var Item = Backbone.Model.extend({ | |
| defaults: { | |
| text: 'hehe' | |
| } | |
| }); | |
| var Todo = Backbone.View.extend({ | |
| id: 'todo', | |
| tagName: 'p', | |
| initialize: function() { | |
| $( '#todo_box' ).html( this.$el ); | |
| this.model = new Item(); | |
| var thatModel = this.model; | |
| _.bindAll( this , 'render' ); | |
| this.listenTo( this.model , 'change' , this.render ); | |
| $( '#change' ).click( function(){ | |
| thatModel.set( 'text' , (new Date())); | |
| }); | |
| this.render(); | |
| }, | |
| render: function(){ | |
| this.$el.append( '<p>' + this.model.get( 'text' ) + '</p>' ); | |
| } | |
| }); | |
| var todo = new Todo(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment