这是我得到的回复(它正在工作):
{"matches":[
{"_core_product_id":"648","finish":"Distressed Green\/Antique Bronze","COUNT(*)":"1"},
{"_core_product_id":"157","finish":"Nightingale Green","COUNT(*)":"1"}],
"count":2}
我想在下拉选择中显示每个类别类别和 COUNT(*)。我没有立即需要,但我可能想要并在自动完成字段之外的其他地方使用 _core_product_id。
这是我的自动完成 jquery 代码:
.autocomplete({
source: function( request, response ) {
$.getJSON( 'controllers/clean/ajax/search.php', {
'fieldid_tableid_type' : this.element[0].id,
'term': extractLast( request.term )
//}, response(['red', 'green', 'blue']) );
},
response );
},
search: function() {
// custom minLength
var term = extractLast( this.value );
if ( term.length < 2 ) {
return false;
}
},
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;
},
delay: 750
});
我不知道在哪里放置“响应”以及如何使用它。任何帮助都会很棒。我知道对此还有其他问题(很多),但我还没有找到一个可以解决我的问题的问题。谢谢。
我注意到 jquery ui 文档显示了在自动完成内部使用的响应。而一些示例在其他地方显示它(例如,就在源内部)。jQuery UI 文档:http ://api.jqueryui.com/autocomplete/#event-response