jQuery UI Autocomplete .result is not a function woes

六眼飞鱼酱① 提交于 2019-12-22 04:56:36

问题


I've done some searching, and this seems to be a not uncommon problem, but none of the solutions posted seem to be working for me.

I've tried a few different methods:

jQuery(document).ready(function(){
    jQuery( "#on-good-terms-add-term" ).autocomplete({
        source: ongoodtermsavailableTags,
    });

    jQuery( "#on-good-terms-add-term" ).result(function(event, data, formatted) { alert(data); });
});

and

jQuery(document).ready(function(){
    jQuery( "#on-good-terms-add-term" ).autocomplete({
        source: ongoodtermsavailableTags,
    }).result(function(event, data, formatted) {
        alert(data);
    });

});

Both give me the same console error. Would appreciate any assistance. Thanks


回答1:


To trigger an event when the user selects a search result with the jQuery UI autocomplete widget, you can initialize your constructor as follows with an event handler for "select":

jQuery("#on-good-terms-add-term").autocomplete({
    source: ongoodtermsavailableTags,
    select: function(e, ui) {
         alert("User selected: " + ui.item.value);
    }
});



回答2:


My error was that I had the file autocomplete-rails.js as well as the provided rails.js in my assets/javascripts folder. Deleting the file was the solution



来源:https://stackoverflow.com/questions/7068504/jquery-ui-autocomplete-result-is-not-a-function-woes

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