Skip to content

Instantly share code, notes, and snippets.

@798bin
Forked from anonymous/jsbin.Awatixo.html
Created November 26, 2013 11:55
Show Gist options
  • Select an option

  • Save 798bin/7657198 to your computer and use it in GitHub Desktop.

Select an option

Save 798bin/7657198 to your computer and use it in GitHub Desktop.
<!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>
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