我有以下代码
$autocompleteSearchInput.each(function() {
const $that = $(this);
$that.autocomplete({
minChars: 4,
serviceUrl: '/internals/site-search',
dataType: 'json',
paramName: 'search_string',
groupBy: 'category',
transformResult: function(response) {
return {
suggestions: $.map(response.results, function(value) {
let node = JSON.parse(value);
let title = (typeof node.field_title !== 'undefined') ? node.field_title[0].value : node.title[0].value;
let data = (typeof node.uri !== 'undefined') ? node.uri : node.path[0].alias;
let type = (node.type[0].target_id === 'property') ? 'Properties' : 'Other Results';
return {
value: title,
data: {
data:data,
category: type
}
};
})
};
},
onSearchComplete: function(query, suggestions) {
if(suggestions.length > 0) {
// add autocomplete-active class to the input when dropdown is show (remove radius on bottom corners)
$that.addClass('autocomplete-active');
}
},
onHint: function(hint) {
return false;
},
onHide: function() {
$that.removeClass('autocomplete-active');
},
onSelect: function (suggestion) {
// If selecting an individual item, direct the user to the node directly
window.location.href = suggestion.data;
}
});
});
使用以下代码类别时,始终显示类别标题。我如何才能做到,如果数据集仅包含“其他结果”或“属性”,那么我们不显示标题?