Skip to content

Instantly share code, notes, and snippets.

@jraines
Created March 14, 2013 16:20
Show Gist options
  • Save jraines/5162754 to your computer and use it in GitHub Desktop.
Save jraines/5162754 to your computer and use it in GitHub Desktop.
Use deferreds in a loop, but keep a reference to something that only exists in each loop iteration
saveQueue: =>
for draft_item in @items.models
attrs = _.clone draft_item.attributes
delete attrs.id
item = new StyliticsBackbone.Models.Item(attrs)
notifyFunction = @_afterSaveFunc(draft_item)
item.save().success(notifyFunction).error(@_notifyError)
_afterSaveFunc: (draft_item) =>
=>
toastr.info('Saved!')
draft_item.destroy()
_notifyError: -> toaster.error('Something went wrong!')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment