Autocomplete with data is not really all that hard. First you need to establish your return type. The easiest tends to be in json format so:
主计长
// be sure to use echo, not return
echo json_encode($yourDataAsArrayOrObject);
这一部分回去了你的 j。
$("#item").autocomplete({
// source should be a url to the controller function that returns the data
source: www.yoursite.com/controller/function ,
search: function(e, ui) {}, // here you can manipulate other elements or items while the data is being retrieved,
select: function(e, ui) { /* ui.item is item slected */ } // here you can manipluate things based on the item that was selected, for instance, save a list of sub data to another dom element
});
最后,
// You will need to use ._renderItem to items as they are received by database.
// For instance, if you want to display the dropdown items in a custom way.
$("#item")._renderItem = function(ul, item) {
// the item. depends on the information you got from server
return ul.append($("<li></li>").prepend($("<h3></h3>").text(item.label)).append($("<p></p>").text(item.value)));
};