views:

26

answers:

1

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>
+1  A: 

you will need to change you controller method to do it.

/GetProducts/{page_index}/{page_size}

you can do it in either by suing something like IQueryable<Products>.skip(page_index*page_size).take(page_size);

or you can pre-define a paging store proc in db, then call it via L2S or EF4

D.J
I think I am a little confused. The answer could only deal with client side JavaScript: How to get the Microsoft JQuery data linker to work on 600 some products as a group rather than link every single property individually.
Dr. Zim