jQuery UI-带有额外参数的自动完成功能-返回的数据 [英] jQuery UI - Autocomplete with extra params - returned data

查看:139
本文介绍了jQuery UI-带有额外参数的自动完成功能-返回的数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

全部

我已经开始使用ui自动完成功能而不是使用插件,我花了一些时间根据我在这里找到的示例来找出额外的参数,但是那部分还是有效的.

I've moved on to using the ui autocomplete rather than the plugin, took me a while to figure out extra params based on an example I found here, but that part works.

我在处理返回数据时遇到问题.在下面的代码中,我可以提醒返回的标题,但在浏览器中会出现未定义"的下拉列表.

I'm having problems with dealing with the return data. In the code below I can alert out the title being returned, but I get a drop down of 'UNDEFINED' in the browser.

谢谢.

    $('#DocTitle').autocomplete({
    source: function(request, response) {
        $.ajax({
            url: "index.pl",
            dataType: "json",
            data: {
                Title: request.term,                        
                maxRows: 10
            },
            success: function(data) {
                response($.map(data, function(item) {
                alert(item.TITLE);
                return {
                    TITLE: item.TITLE

                }
            }))
            }
        })
    }
});

推荐答案

我正在按如下方式使用jquery UI自动完成功能,并且对我来说效果很好.您可以尝试类似的方法.

I am using jquery UI autocomplete as follows and it is working quite fine for me. You may try on the similar lines.

$('input[type=text][name=City]').autocomplete({
            source: function(request, response) {
                $.getJSON($('input#CitySuggestionsLink').val(), {
                    term: request.term,
                    stateId: $('select#StateName option:selected').attr('value')
                }, response);
            },
            search: function() {
                // custom minLength
                var term = this.value;
                if (term.length < 1) {
                    return false;
                }
            },
            delay: 200,
            focus: function() {
                // prevent value inserted on focus
                return false;
            },
            select: function(event, ui) {
                return false;
            }
        });

这篇关于jQuery UI-带有额外参数的自动完成功能-返回的数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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