Created
November 21, 2012 17:06
-
-
Save billybonks/4126084 to your computer and use it in GitHub Desktop.
this function will merge two objects dependent on a path
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
/* | |
given that | |
ObjectA = sourceObject | |
ObjectB = destinationObject | |
it will fill Object b with the field in Object A | |
ObjectA{ | |
SomeField.InnerField : data | |
} | |
ObjectB{ | |
SomeField{ | |
InnerField : data | |
} | |
} | |
*/ | |
function MergeObjects (sourceObject,destinationObject){ | |
for(field in sourceObject){ | |
var path = field.split('.'); | |
var destinationpathObject = 'destinationObject' | |
for(subpath in path){ | |
destinationpathObject+='["'+[path[subpath]]+'"]'; | |
} | |
//destinationObject[AssignedTo][Name]; | |
eval(destinationpathObject + " = sourceObject[field]")// = sourceObject[field]; | |
} | |
return destinationObject; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment