jQuery UI autocomplete refresh data

纵饮孤独 提交于 2019-12-03 03:36:29

When you update the color, you need to also update the source that autocomplete uses, like this:

function addColor() {
    //add colors
    $('#empf').autocomplete("option", { source: colors });
}

Here's a sample demo doing this, adding a color and updating the autocomplete source once a second.

I've tried Nick Craver's solution, which looks completely logical. Maybe, it is because I am using a URL string rather than an array as the 'source'. Unfortunately his solution does not do a live refresh for the ajax data returned. In order to refresh an ajax data source, I found that the following works:

element.autocomplete("option","source",url);
element.autocomplete("search");

I think the 'search' method is required for string or ajax URL source types.

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