I am retrieving some JSON data with the following function. It is called when an element is clicked and the data is used to create a table, populate the cells with images and append the table to a div.
function LoadImagesByCategory() {
$.getJSON("/Service/GetJson.ashx?data=images", function(data) {
jsObjectData = data.ImageCollection.Images;
//Create a table named imageTable
$("#imagesByCategory").append(imageTable);
}
})
the jsObjectData looks like this.
{"ImageCollection":
{"Images":
[{ "ImageID":"68",
"CatID":"1",
"Name":"uploadedFile",
"Location":"/Images/Art/Full/68.gif",
"ClipLocation":"/Images/Art/Clips/68.gif",
"FullHeight":"504",
"FullWidth":"451"
},
{ "ImageID":"69",
"CatID":"1",
"Name":"uploadedFile",
"Location":"/Images/Art/Full/69.gif",
"ClipLocation":"/Images/Art/Clips/69.gif",
"FullHeight":"364",
"FullWidth":"500"
},
etc. etc
]
}
}
It contains additional info about the images like the FullHeight and the FullWidth that I would like to be able to retrieve when an img is clicked.
For example if I made the id of the img something like “68ArtImage” where 68 is the ImageID I would like to be able to pass the 68 into a function attached to the jsObjectData and retrieve the corresponding Image Data.
The problems are first that I don’t know how to make the object avail. outside the function and second I don’t know how to attach the function to the object.
After reading your question again, perhaps this is what you want?
getImageDatawill search the given json object and return the image object (like an associative array) if it exists, else false.Example: