I have the following objects:
var myObj =
{
prop1 : 'val',
prop2 : 'val'
},
hisObj =
{
prop1 : 'val',
prop2 : 'val'
},
herObj =
{
prop1 : 'val',
prop2 : 'val'
};
Now I run an ajax call and return 3 sets of data as arrays. The key of each of these arrays is equal to: my, his and her.
How would I assign the correct object to a private variable within a function that deals with the ajax response. I tried this to start:
function ajax_callback(data)
{
$.each( data, function( key , value )
{
var options = key + 'Obj';
...
});
};
var options in this case is rightly of type string. How would I have dynamically created the variable options to contain the correct object rather than a string representation of it’s name?
I’m not sure what you are trying to achieve here. But you probably need to “namespace” your objects inside another object. How about:
Or if you want to pluck an entry from the object based on your response key: