Skip to content

Instantly share code, notes, and snippets.

@dchentech
Created February 28, 2014 04:06
Show Gist options
  • Save dchentech/9265064 to your computer and use it in GitHub Desktop.
Save dchentech/9265064 to your computer and use it in GitHub Desktop.
Backbone View 随数据改变而render。
$(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