jQuery Autocomplete & jTemplates - handling response

Posted by Diegos Grace on Stack Overflow See other posts from Stack Overflow or by Diegos Grace
Published on 2010-06-01T02:17:47Z Indexed on 2010/06/01 2:23 UTC
Read the original article Hit count: 352

Filed under:
|
|

Has anyone had any experience with using jTemplates to display autocomplete results.

I have the following

$("#address-search").autocomplete({
    source: "/Address/SearchAddress",
    minLength: 2,
    delay: 400,
    focus: function (event, ui) {
      $('#address-search').val(ui.item.name);
       return false;
    },
    parse: function(data) {
      $("#autocomplete-results").setTemplate($("#templateHolder").html());
      $("#autocomplete-results").processTemplate(data);
    },
    select: function (event, ui) {
    $('#address-search').val(ui.item.name);
    $('#search-address-id').val(ui.item.id);
    $('#search-description').html(ui.item.address);

    });

and the simple jtemplate holder:

<script type="text/html" id="templateHolder">
    <ul class="autocomplete">
        {#foreach $T as data}
        <li>{$T.name}</li>
        {#/for}
    </ul>
</script>

Above i'm using 'Parse' to format results, I've also tried the autocomplete result method but not having any luck so far. The only success I've had is by using the private method ._renderItem and formatting the data that way but we want to render the output using the jTemplate.

Any advice appreciated.

© Stack Overflow or respective owner

Related posts about jquery-ui

Related posts about autocomplete