如果未找到任何内容,则从 jquery ui 自动完成中删除微调器 [英] remove spinner from jquery ui autocomplete if nothing found

查看:15
本文介绍了如果未找到任何内容,则从 jquery ui 自动完成中删除微调器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想从支持 jquery ui 自动完成的文本字段中删除微调器(显示它正在加载的图片).由于没有源没有返回结果"的事件,因此无法触发.

I want to remove the spinner (picture which shows that it is loading) from the textfield which supports jquery ui autocomplete. As there is no event for "no results returned by source" a can not trigger this.

$( "#q" ).autocomplete({
   source: "${createLink(mapping:'qsearch')}",
   minLength: 2,
   select: function( event, ui ) {
      foo( ui.item.id );
   },
   search: function( event, ui ) {
      bla();
   }
});

推荐答案

改编自我的回答这里,添加以下内容搜索完成后执行的代码(即使有 0 个结果):

Adapted from my answer here, add the following code to execute after a search is complete (even with 0 results):

var __response = $.ui.autocomplete.prototype._response;
$.ui.autocomplete.prototype._response = function(content) {
    __response.apply(this, [content]);
    this.element.trigger("autocompletesearchcomplete", [content]);
};

该代码将触发一个事件 (autocompletesearchcomplete),然后您可以绑定到该事件:

That code will trigger an event (autocompletesearchcomplete) that you can then bind to:

$("#q").bind("autocompletesearchcomplete", function(event, contents) {
    /* Remove spinner here */
});

希望有所帮助.

这篇关于如果未找到任何内容,则从 jquery ui 自动完成中删除微调器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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