我如何知道渲染函数中视图模型的哪个属性发生了变化?(在渲染函数中,“e”是模型,但我只需要更改的属性。)我需要知道这一点才能知道要使用哪个模板。还是有另一种方法可以做到这一点?
window.Person = Backbone.Model.extend({});
window.Njerzit = Backbone.Collection.extend({
model: Person,
url: '/Home/Njerzit'
});
window.PersonView = Backbone.View.extend({
tagName: 'span',
initialize: function () {
_.bindAll(this, 'render');
this.model.bind('change', this.render);
},
render: function (e) {
//if model name is changed, I need to render another template
this.template = _.template($('#PersonTemplate').html());
var renderContent = this.template(this.model.toJSON());
$(this.el).html(renderContent);
return this;
}
});