How to find out which attribute of the view model is changed in the rendering function? (In the rendering function, โeโ is a model, but I only need the attribute that has been changed.) I need to know this to find out which template to use. Or is there another way to do this?
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; } });
source share