我正在使用jQuery UI的自动完成功能来从远程源提供搜索输入框的建议.我有"远程数据源"示例正常工作.例如,这有效:
$("#search").autocomplete({
source: "search_basic.php",
minLength: 2
});
Run Code Online (Sandbox Code Playgroud)
但是,我想使用" 类别 "示例按类别对建议进行排序.来自jQuery UI站点的示例,内联数据集正常工作:
<script>
$.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 );
});
}
});
$(function() {
var data = [
{ label: "anders", category: "" },
{ label: "andreas", category: "" …Run Code Online (Sandbox Code Playgroud)