With an extreme amount of SO user help, I used ASP.NET MVC 2 Futures to employ JSON to load 600 some products and display them with Microsoft Jquery templates in 400ms with the code below.
Is there a way to use Microsoft JQuery Linking to bind the object to the generated form data without looping through every one? (Assuming I preserve the "j" object outside the anonymous function)
I guess I should remove the IDs and unique names, just letting them be property names (and use classes). Could you do some sort of JQuery selector with a .link behind it, selecting multiples and applying the link method to all?
// adDate and printProduct are grouping keys to extract a set from the Product List
function onClickGetProducts()
{ var adDateValue = $('#adDates option:selected').val();
var printProductValue = $('#printProducts option:selected').val();
var responseObject = {};
responseObject.adDate = adDateValue;
responseObject.printProduct = printProductValue;
var jsonResult = JSON.stringify(responseObject);
$.ajax({ type: "POST",
url: "/GetProducts",
data: jsonResult,
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function (j) {
// TODO: do something with products
$('#Products').html('');
$('#productTemplate').tmpl(j).appendTo("#Products");
}
});
}
Template code:
<script id="productTemplate" type="text/x-jquery-tmpl">
<div style="position:relative;float:left;background-color:White;:400px;height:250px;overflow:scroll;">
<b>#${upc}</b><br />
----<br />
Main Product Text:<br/>
<input type="text" value="${maintext}" name="product${h_adv_nbr}" /><br />
Description Text:<br/>
<input type="text" value="${desctext}" name="product${h_adv_nbr}" /><br />
Photo:<br/>
<input type="text" value="${photo}" name="product${h_adv_nbr}" /><br />
</div>
</script>