javascript - Backbone: How to prevent overriding jQuery Ajax methods by Backbone Ajax functions? -
very interesting situation!
the code below represents order entry. before saving user should calc order total clicking on #calctotal button , clicks on #saveorder button.
the problem if user launches saveorder function 1 time ajax method in calctotal function call model.save in saveorder function!
i think this.model.save function override backbone model functions ajax request execute actions in model.save.
how should prevent behaviour?
events: { 'click #calctotal': 'calctotal', 'click #saveorder': 'saveorder' }, calctotal: function() { this.model.set( $('form').serializejson() ); var = this; $.ajax({ url: 'api/order/calctotal', type: 'get', data: this.model.tojson(), datatype: 'json', success: function( result ) { that.model.set({ 'total': result.total }); that.rendertotal(); } }); }, saveorder: function() { var = this; this.model.save({ success: function() { console.log('check'); } }); },
Comments
Post a Comment