简体   繁体   English

我如何从jQuery UI自动完成呈现列表中删除项目

[英]How can i remove item from jquery ui autocomplete rendered list

i want to remove item from jquery-ui autocomplete rendered list 我想从jquery-ui autocomplete呈现列表中删除item

let say the item is compton 假设该物品是康普顿

Question : i want to remove item "compton" once it is rendered from outside NOT from helper functions like select,create,open etc 问题 :我想从外部渲染item “康普顿”,而不是从 select,create,open等辅助功能中删除

Below is my code: 下面是我的代码:

  $(function() { var availableTags = [ "john", "khair", "compton", "Jordan", "Micheal", "Peter" ]; $( "#tags" ).autocomplete({ source: availableTags }).focus(function () { $("#tags").autocomplete("search"); }); // logic to remove item "compton" must reflect in rendered ui }); 
 <link href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.16/themes/base/jquery-ui.css" rel="stylesheet"/> <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script> <script src="https://cdnjs.cloudflare.com/ajax/libs/jqueryui/1.12.1/jquery-ui.min.js"></script> <div class="ui-widget"> <label for="tags">Search: </label> <input id="tags"> </div> 

Try using option method which sets one or more options for the autocomplete. 尝试使用为自动完成功能设置一个或多个选项的option 方法

 $(function() { var availableTags = [ "john", "khair", "compton", "Jordan", "Micheal", "Peter" ]; $("#tags").autocomplete({ source: availableTags }).focus(function() { $("#tags").autocomplete("search"); }); $("#tags").autocomplete("option", "source", availableTags.filter(i => i !== "compton")); }); 
 <link href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.16/themes/base/jquery-ui.css" rel="stylesheet" /> <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script> <script src="https://cdnjs.cloudflare.com/ajax/libs/jqueryui/1.12.1/jquery-ui.min.js"></script> <div class="ui-widget"> <label for="tags">Search: </label> <input id="tags"> </div> 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM