Created
February 28, 2014 04:06
-
-
Save dchentech/9265064 to your computer and use it in GitHub Desktop.
Backbone View 随数据改变而render。
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
$(document).ready(function() { | |
var dom = $("<div>").attr('id', 'mvj3'); | |
$("body").html(dom); | |
window.mvj3 = Backbone.View.extend({ | |
initialize: function(opts) { | |
this.opts = opts; | |
return this; | |
}, | |
tagName: "div", | |
render: function() { | |
this.$el.html(this.template({opts: this.opts})); | |
return this; | |
}, | |
template: _.template("<h1>改变之: <%= opts.hello %></h1>") | |
}); | |
window.m = new mvj3({hello: "Ruby"}); | |
dom.html(m.el); | |
m.render(); | |
m.opts.hello = 'Python'; | |
setTimeout(function() { m.render(); }, 3000); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment