I have two objects returned from two different rest resources.
{
"id": 1,
"username": "jdoe"
}
{
"role_id": 1,
"role": "developer",
"members": [
1,
3,
5
]
}
I’d like to use plain ole javascript to combine these two objects based into one where id is in the members array, so that i get back an object like has roles as the top node, then lists users of that role underneath.
Easily done?
I had a similar problem a couple weeks ago with a set of 10 AJAX calls that I wanted to mesh together. A simple method is to create a lookup table from the
idvalues, then use the lookup table to combine the results. Here’s an example using multiple users and multiple roles:Now the members in roles are references to the users rather than just the id’s:
And you can reference the usernames in a role like this:
Demo: http://jsfiddle.net/2aqR5/1/