trigger search from select within jquery ui autocomplete

馋奶兔 提交于 2020-03-28 05:00:35

问题


How do I trigger/call jQuery UI Autocomplete event handlers from each other, for example, triggering a search from the select handler?

Thx, Lille


回答1:


To trigger a search:

$("#my-autocomplete").autocomplete("search", "SearchTerm");

In general, call jQueryUI widget methods using $("selector").widget("method" /*, options */)




回答2:


The answer above is only valid for jQueryUI 1.8.x Since jQueryUI 1.9.x you must add a timeout:

scott.gonzalez says: "There were some pretty big changes to autocomplete between 1.8 and 1.9, specifically selection is now synchronous where before it was asynchronous."

more:

scott.gonzalez says: "What's happening is selecting an item always closes the menu. Closing the menu tells the autocomplete to ignore any pending searches. This includes the search that you're manually triggering immediately before the menu closes. It's also worth noting that you're running a duplicative search, since you're triggering the search before the value updates."

select: function(event, ui)
{
    var that = $(this);            
    setTimeout(function() {
      that.autocomplete("search");
    }, 1);
},

Example: http://jsfiddle.net/RB4N3/



来源:https://stackoverflow.com/questions/12984151/trigger-search-from-select-within-jquery-ui-autocomplete

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!