0

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]
4

1 に答える 1

0

バックボーン モデル自体でトリガーしたいと思います。を見てみましょう:

http://backbonejs.org/#trigger

于 2012-09-03T23:59:05.397 に答える