Created
March 14, 2013 16:20
-
-
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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