jQuery的自动完成功能和安培; jTemplates - 响应处理 [英] jQuery Autocomplete & jTemplates - handling response

查看:138
本文介绍了jQuery的自动完成功能和安培; jTemplates - 响应处理的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有人有任何经验,使用jTemplates显示自动完成结果。

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

我有以下

$("#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);

    });

和简单的jtemplate持有人:

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>

在上面,我用解析,以格式的结果,我也试着自动完成结果的方法,但没有到目前为止,运气好的话。我有过的唯一的成功是使用私有方法._renderItem和格式化这种方式中的数据,但我们想渲染使用jTemplate输出。

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.

任何意见AP preciated。

Any advice appreciated.

推荐答案

什么样的​​问题,你遇到了?只是看着你的code真正的快,好像你可能不会得到你想要的值到模板,也可能是示数了呢?在你的的foreach ,你调用单个对象阵列数据,但是你追加的价值 {$ T.n​​ame} 。也许你想 {$ T.data.name} 呢?

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?

这篇关于jQuery的自动完成功能和安培; jTemplates - 响应处理的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆