jquery-ui 自动完成零星行为

发布于 2024-11-29 12:58:48 字数 1123 浏览 1 评论 0原文

下面是我的自动完成代码。问题是它大部分都有效。假设我有一堆结果,例如 test1、test2、test3 等。如果我输入“t”,它们就会弹出,当我在“te”中输入 e 时,它​​们就会消失。然后,如果我输入“s”,它会进一步缩小范围。它也不总是第二个字母。看起来只是零星的。请帮忙。我已经确认返回的数据是可靠的,因此后端没有任何数据。

        //Server autocomplete
        $("#txtSearchServer").keyup(function (event) {
            $.ajax({
                url: 'edit/EditService.svc/SearchServers',
                type: 'GET',
                data: { 'term': $("#txtSearchServer").val() },
                dataType: 'json',
                success: function (data) {
                    var listServers = [];
                    $.map(data.d, function (item) {
                        ///working here to do server autocomplete!!!!!!!
                        listServers.push(item.ServerName);
                        $("#txtSearchServer").autocomplete({
                            source: listServers
                        });
                    });
                },
                error: function (a, b, c) {
                    $('.Toast').html('Error Retreiving Servers for autocomplete!');
                }
            });
        });

Below is the code for my autocomplete. The problem is that it mostly works. Say I have a bunch of results that are like test1, test2, test3, etc. If I type "t" they popup, when I put an e in "te" they disappear. Then if I put in the "s" it narrows it down further. it's not always the second letter either. It just seems sporadic. Please help. I have confirmed the data coming back is solid, so it's nothing on the backend.

        //Server autocomplete
        $("#txtSearchServer").keyup(function (event) {
            $.ajax({
                url: 'edit/EditService.svc/SearchServers',
                type: 'GET',
                data: { 'term': $("#txtSearchServer").val() },
                dataType: 'json',
                success: function (data) {
                    var listServers = [];
                    $.map(data.d, function (item) {
                        ///working here to do server autocomplete!!!!!!!
                        listServers.push(item.ServerName);
                        $("#txtSearchServer").autocomplete({
                            source: listServers
                        });
                    });
                },
                error: function (a, b, c) {
                    $('.Toast').html('Error Retreiving Servers for autocomplete!');
                }
            });
        });

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

彼岸花ソ最美的依靠 2024-12-06 12:58:48

看看你正在做的 asp.net 代码,

所以这应该适合你:

function AutocompleteJSONParse(data) {
    var rows = new Array();
    var rowData = null;
    for (var i = 0, dataLength = data.length; i < dataLength; i++) {
        rowData = data[i];
        rows[i] = {
            value: rowData.ServerName,
            label: rowData.ServerName
        };
    }
    return rows;
};
$("#txtSearchServer").autocomplete({
    source: function(request, response) {
        var pString = '{"term":"' + request.term + '"}';
        $.ajax({
            url: 'edit/EditService.svc/SearchServers',
            type: 'GET',
            dataType: "jsond",
            type: "POST",
            contentType: "application/json",
            converters: {
                "json jsond": function(msg) {
                    return msg.hasOwnProperty('d') ? msg.d : msg;
                }
            },
            data: pString,
            success: function(data) {
                var rows = AutocompleteJSONParse(data);
                response(rows);
            }
        });
    },
    error: function(a, b, c) {
        $('.Toast').html('Error Retreiving Servers for autocomplete!');
    },
    minLength: 2,
    delay: 1000
});

Looking at your code you are doing asp.net

SO this should work for you:

function AutocompleteJSONParse(data) {
    var rows = new Array();
    var rowData = null;
    for (var i = 0, dataLength = data.length; i < dataLength; i++) {
        rowData = data[i];
        rows[i] = {
            value: rowData.ServerName,
            label: rowData.ServerName
        };
    }
    return rows;
};
$("#txtSearchServer").autocomplete({
    source: function(request, response) {
        var pString = '{"term":"' + request.term + '"}';
        $.ajax({
            url: 'edit/EditService.svc/SearchServers',
            type: 'GET',
            dataType: "jsond",
            type: "POST",
            contentType: "application/json",
            converters: {
                "json jsond": function(msg) {
                    return msg.hasOwnProperty('d') ? msg.d : msg;
                }
            },
            data: pString,
            success: function(data) {
                var rows = AutocompleteJSONParse(data);
                response(rows);
            }
        });
    },
    error: function(a, b, c) {
        $('.Toast').html('Error Retreiving Servers for autocomplete!');
    },
    minLength: 2,
    delay: 1000
});
蓝眼泪 2024-12-06 12:58:48

这是答案: https://gist.github.com/1140631 应该可以解决这个问题。

编辑:我还想知道为什么你要动态预取结果,你不能立即获得完整列表吗?还是数据太多了?

Here is the answer: https://gist.github.com/1140631 that should solve it.

EDIT: I was wondering also why are you dynamically prefetching results, can't you get full list right away? Or is it to much data?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文