views:

108

answers:

1

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.

A: 

What kind of issues are you running into? Just looking at your code real quick, it seems like you may not be getting the values you want into the template, or it may be erroring out? Within your foreach, you're calling the individual objects in your array data, but you're appending the value of {$T.name}. Maybe you want {$T.data.name} instead?

garann