我需要对AutoComplete结果进行分组,我发现了以下解决方案.我怎样才能找出所选建议的类别?
例如,假设有城市和国家类别,用户选择其中一个城市.我怎么知道所选项目是城市的一部分而不是国家类别(当表格提交时)?我也不希望用户可以看到类别名称.
到目前为止我发现了什么
$.widget( "custom.catcomplete", $.ui.autocomplete, {
_renderMenu: function( ul, items ) {
var self = this,
currentCategory = "";
$.each( items, function( index, item ) {
if ( item.category != currentCategory ) {
ul.append( "<li class='ui-autocomplete-category'>" + item.category + "</li>" );
currentCategory = item.category;
}
self._renderItem( ul, item );
});
}
});
Run Code Online (Sandbox Code Playgroud)
我的守则
$(function() {
$("#box1").autocomplete({
source: function(e, r) {
var t, s = "http://localhost:8080/MyProject/autoComplete/box1";
$.ajax({
url: s,
dataType: "json",
data: {
q: e.term
},
success: function(e) …Run Code Online (Sandbox Code Playgroud)