我尝试在模型更改时渲染视图。你能告诉为什么这段代码不能正常工作吗?
var TodoView = Backbone.View.extend({
initialize: function() {
this.model.on('change', this.render, this);
},
});
它给出了错误:
TypeError: this.model.on is not a function
但看起来这段代码有效:
var TodoView = Backbone.View.extend({
initialize: function() {
_.bindAll(this, 'render');
this.model.bind('change', this.render);
},
});
这些库用于:
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.0/jquery.min.js"></script>
<script src="http://ajax.cdnjs.com/ajax/libs/underscore.js/1.1.4/underscore-min.js"></script>
<script src="http://ajax.cdnjs.com/ajax/libs/backbone.js/0.3.3/backbone-min.js"></script>