Skip to content

Instantly share code, notes, and snippets.

@paulwsmith
Last active August 29, 2015 14:14
Show Gist options
  • Save paulwsmith/2b4fc1ad3956d1b3466a to your computer and use it in GitHub Desktop.
Save paulwsmith/2b4fc1ad3956d1b3466a to your computer and use it in GitHub Desktop.
znRecordOverlay.open({
onSubmit: function(submittedData, onComplete) {
var newRecord = {};
angular.extend(newRecord, submittedData);
console.log(newRecord.id); // error
$scope.recordList.push(submittedData);
onComplete.then(function(serverData) {
// each onSave and "included" onComplete promise are connected by being in closure together
// you can have as many as you want and they won't interact with each other
angular.extend(newRecord, serverData);
console.log(newRecord.id); // works
});
}
});
var newRecords = {};
znRecordOverlay.open({
onSubmit: function(recordData) {
console.log(recordData.id); // error
newRecords[recordData.localId] = recordData;
$scope.recordList.push(newRecords[recordData.localId]);
},
onComplete: function(moreData) {
// Need to use localId or something else to know which "onSubmit" record this ties to
angular.extend(newRecords[moreData.localId], moreData); // need to make sure "localId" is provided here
console.log(newRecords[moreData.localId].id); // works
}
});
// If you're working with multiple records you can use only "onComplete" to keep it simpler
// But then you're using 2 different paradigms for single vs. multiple
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment