I'm looking for the best way to build some HTML 'objects' based on an array of jQuery objects that I have created. I then need each one to be clickable, and pull the values from the one that was clicked.
A bit of background...I'm building the objects from ajax calls to a external API service. The user searches for a name, then I end up with an array of objects with three properties (Id, ImageUrl, and Name).
I'm wondering if there is a 'easy'/clean way to display the Name and Image of the object and make it clickable...then when the object is clicked, I want to pass that Id back to the controller, which will in turn display a details page for the selected object.
What I currently have is all the jQuery to build the object, and then a results section:
<div id="results"> </div>
Then in the jQuery I call a function that appends to the div tag:
var div = $("<div class='well clearfix'>");
div.append($("<h4>").html(item.name));
I think the main concern is how to build the div tag in such a way that I can easily retrieve the Id of the object once it is clicked and pass it back to the controller.
data-attributes, read with jquerydata()method