1
我想实现一个jQuery自动完成功能类别和阿贾克斯,自动完成与类别
我有以下的javascript,我从Jquery UI website有:
<script>
$.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);
});
}
});
</script>
<script type="text/javascript">
$(function() {
//autocomplete
$(".auto").autocomplete({
source: "autocomplete.php",
minLength: 1,
});
});
</script>
和文件autocomplete.php
呼应JSON数组一样这个:
[
{"label":"Sandy W","category":"Artist"},
{"label":"Shlomi Aber & Itamar Sagi","category":"Artist"},
{"label":"sad","category":"Keyword"}
]
但是,它似乎像jquery不承认的类别。当数组显示在自动完成列表中时,数组中的值不会根据它们的类别分开。
难道是Json附近的报价label
和categories
?我注意到,在由jquery label
和categories
提供的示例中没有引号。
感谢您的帮助:)
我怎么能错过这...谢谢! :) – anto0522