0
votes

I'm overriding Backbone.sync for a model so that I can send calls out to the appropriate URLs when some conditions are met. How do I trigger a success or error callback like I would in .save? Adding a save method to my model doesn't work, as it seems to balk at the new URL.

Code example below (coffeescript) :

  sync: (method, model, options) ->
    if options.changes.approval is true
      options.url = @approvalUrl()
    else if options.changes.decline is true
      options.url = @declineUrl()
    else
      return false
    Backbone.sync method, model, options

On success I'd like to fire the following trigger, which normally I could do with success: (model, response), but can't get working here

jQuery(".user-line-item-summary").trigger "approveSucceeded", [@get("id"), msg, false]
1

1 Answers

0
votes

I think you want to trigger on the backbone model itself. Take a look at:

http://backbonejs.org/#trigger