jQuery UI自动完成类别不显示
知道类别返回未定义的原因吗 我得到的项目,但不是类别jQuery UI自动完成类别不显示,jquery,json,jquery-ui,autocomplete,jquery-ui-autocomplete,Jquery,Json,Jquery Ui,Autocomplete,Jquery Ui Autocomplete,知道类别返回未定义的原因吗 我得到的项目,但不是类别 $.widget( "custom.catcomplete", $.ui.autocomplete, { _renderMenu: function( ul, items ) { var that = this, currentCategory = ""; $.each( items, function( index, item ) {
$.widget( "custom.catcomplete", $.ui.autocomplete, {
_renderMenu: function( ul, items ) {
var that = this,
currentCategory = "";
$.each( items, function( index, item ) {
if ( item.category != currentCategory ) {
ul.append( "<li class='ui-autocomplete-category'>" + item.category + "</li>" );
currentCategory = item.category;
}
that._renderItemData( ul, item );
});
}
});
function split( val ) {
return val.split( /,\s*/ );
}
function extractLast( term ) {
return split( term ).pop();
}
$("#people_q:not(.ui-autocomplete-input)").live("keyup", function (event) {
$(this).catcomplete({
source: function (request, response) {
$.ajax({
url: "/json/people_search.asp",
dataType: "json",
data: {
q:extractLast( request.term )
},
success: function (data) {
response($.map(data.results.result, function (item) {
return {
label: item.sresult,
value: item.sresult
};
}));
}
});
},
minLength: 2,
open: function () {
$(this).removeClass("ui-corner-all").addClass("ui-corner-top");
},
close: function () {
$(this).removeClass("ui-corner-top").addClass("ui-corner-all");
},
focus: function() {
// prevent value inserted on focus
return false;
},
select: function( event, ui ) {
var terms = split( this.value );
// remove the current input
terms.pop();
// add the selected item
terms.push( ui.item.value );
// add placeholder to get the comma-and-space at the end
terms.push( "" );
this.value = terms.join( ", " );
return false;
}
});
});
您提供的
响应
回调的数据不包括每个项目的类别
。您应该可以这样更改success
回调:
success: function (data) {
response($.map(data.results.result, function (item) {
return {
label: item.sresult,
value: item.sresult,
category: item.category // <-----
};
}));
}
成功:函数(数据){
响应($.map)(data.results.result,函数(项){
返回{
标签:item.sresult,
值:item.sresult,
类别:item.category//
success: function (data) {
response($.map(data.results.result, function (item) {
return {
label: item.sresult,
value: item.sresult,
category: item.category // <-----
};
}));
}