进入一个前所未有搜索词时,jQuery UI的自动完成功能不触发搜索 [英] jQuery UI Autocomplete not triggering a search when entering a hitherto searched for term

查看:97
本文介绍了进入一个前所未有搜索词时,jQuery UI的自动完成功能不触发搜索的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有当的minLength = 3的问题如下将触发一个Ajax请求的jQuery用户界面自动完成控制:
说我进入FIC作为初始搜索词 - 这是好的。请求火灾和返回结果。我决定,我不希望任何选择的结果,然后再重新输入相同的搜索(FIC)。这一次没有Ajax请求火灾!

I have a jQuery UI Autocomplete control that fires an Ajax request when minLength = 3. The problem is as follows: Say I enter "fic" as the initial search term - this is fine. The request fires and results are returned. I decide that I don't want to select any of the results and then re-enter the same search again (fic). This time no Ajax request fires!

我的code如下所示:

My code is shown below:

// ... do request
$("#reportSearch").autocomplete({
    delay: 50,
    minLength: 3,
    source: function(q, add){
        $.ajaxSetup ({ cache: false});              
        $.ajax({
            type: "GET",
            url: K_URL_REQUEST



所以基本上源回调不是在我上述的第二个场景解雇。现在看来,这样做的原因是,自动完成控制拿着到previous搜索词,因为它匹配的 - 没有触发搜索:



So basically the "source" callback is not fired in the second scenario I described above. It appeared that the reason for this was that the autocomplete control was holding onto the previous search term and because it matched - was not triggering a search:

// Taken from jquery-ui-1.8.4.custom.min.js
if (a.term != a.element.val()) { // *** THE MATCH IS HERE
    //console.log("a.term != a.element.val(): "+a.term+", "+a.element.val());
    a.selectedItem = null;
    a.search(null, c) // *** SEARCH IS TRIGGERED HERE
}


为了得到它的每一次火,我只是搜索词重置为空搜索返回之后。这样一来,它的工作如预期。

In order to get it to fire each time, I simply reset the search term to null after a search returned. This way it worked as expected.

问题是我不理解这种行为。我就已经想到每个搜索应该是不同的。没有高速缓存(或不应该是这样)。

The thing is I don't understand this behaviour. I would've thought each search should be distinct. There is no caching (or shouldn't be anyway).

所以,虽然我已经解决我的问题,我一直觉得我已经错过了的东西在这里。

So although I've fixed my problem I keep feeling that I have missed something here.

任何想法的人?在此先感谢!

Any ideas anyone? Thanks in advance!

推荐答案

我已经找到了解决这个问题(信息,我使用jQuery UI 1.8.4)

I have found a solution to this problem (for info, I am using jQuery UI 1.8.4)

在jQuery的-UI-1.8.4.custom.js自动完成实施具有被定义为_change的方法。通过注释掉的如果的声明,控制总发送请求。

The Autocomplete implementation in the jquery-ui-1.8.4.custom.js has a method defined as _change. By commenting out the if statement, the control always sends the request.

...,
_change: function(event) {
    //if (this.previous !== this.element.val()) {
        this._trigger("change", event, { item: this.selectedItem });
    //}
},
...

这篇关于进入一个前所未有搜索词时,jQuery UI的自动完成功能不触发搜索的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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