is there any way I can get the return of $.getJSON into a variable array?
I know its async and out of scope, but I will use it inside ajax callback, I just need to get all the values first and check them against another array.
Something like:
$.getJSON('itemManager.php?a=getItems', function(data){
// itemArray = new Array(data);
// idsArray = new Array(data.id);
for (var i in someOtherArray){
if($.inArray(i, idsArray) == -1){
// do something...
// get jason variable by id?
// itemArray[i].someVariable
}
}
}
EDIT: JSON structure
[{"id":"786","user_id":"1","seller_id":"2","address_id":"1","time":1299852115,"publicComment":null,"personalComment":null},
{"id":"787","user_id":"1","seller_id":"2","address_id":"1","time":1299852115,"publicComment":null,"personalComment":null},
{"id":"785","user_id":"1","seller_id":"2","address_id":"1","time":1299852114,"publicComment":null,"personalComment":null},
{"id":"784","user_id":"1","seller_id":"2","address_id":"1","time":1299852113,"publicComment":null,"personalComment":null},
{"id":"783","user_id":"1","seller_id":"2","address_id":"1","time":1299852111,"publicComment":null,"personalComment":null}]
This is basically the idea.
- Get all the values
- Isolate the id values of JSON objects
- Loop another array
- Check if json id is inside the other array
- Access other json variables by id value
There are various solutions here I guess, but I'm looking for something with minimal code.
idsArray = new Array(data.id)
does not look right). – Felix Kling Mar 11 '11 at 13:46someOtherArray
look like and what is the value ofdata
? If we don't know the structure, we cannot tell you how to access it. And this is not related to jQuery at all, just basic JavaScript. – Felix Kling Mar 11 '11 at 13:49data
? Is it a single object or is it an array of objects? Why not just post the structure, makes it much easier. – Felix Kling Mar 11 '11 at 13:53