本文介绍了jQuery自动完成结果顺序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 jQuery-autocomplete插件来获取有关使用输入法完成输入字符串的建议对服务器的AJAX调用.另外,服务器负责按照我希望它们出现的顺序返回结果,但是自动完成功能以不同的顺序显示它们.

I am using the jQuery-autocomplete plugin to get suggestions for completion of the input string using an AJAX call to a server. Also, the server takes care of returning the results in the order I would want them to appear but autocomplete shows them in a different order.

如何配置jQuery自动完成功能以不对输出重新排序?我不需要在客户端进行任何形式的处理,因为数据已经按要求进行了排名/排序.

How can I configure jQuery autocomplete to not reorder the output ? I don't require any kind of processing on the client's end as the data has already been ranked/sorted as required.

推荐答案

好吧,事实证明它比我想象的要简单.我决定阅读该插件的代码,并通过注释掉对我的输出进行排序的代码来对其进行修改.

Well, it turned out to be simpler than I thought. I decided to read the code of the plugin and modify it by commenting out the code that sorts my output.

那是我在默认情况下找到变量'sortResults:true'的时候.因此,我所需要做的就是将该变量设置为false.我在文档中没有找到这个.

That is when I found a variable 'sortResults:true' in defaults. So, all I needed was to set that variable to false. I didn't find this in the documentation though.

$('#search').autocomplete ( { url: "index.php", sortResults: false } )

现在输出的顺序与我要求的完全相同.

Now the output is in the exact order that I require.

我的想法是从此处阅读代码以查找/解决问题:(不是同一个插件)

I got the idea of reading the code to find/solve the problem from here : jQuery "Autocomplete" plugin is messing up the order of my data(That isn't the same plugin)

谢谢. :)

这篇关于jQuery自动完成结果顺序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-05 12:27