0
我正在使用JQuery自動填充類別讓用戶從列表中選擇一個項目。允許用戶添加項目到JQuery自動完成類別
我現在想要做的是讓用戶添加一個新的項目到兩個可用的類別之一。
這是我現在有:
HTML:
<input id="procura"></input>
JS:
$.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() {
var data = [{
label: "Vendas",
category: "Recebimentos"
}, {
label: "Serviços",
category: "Recebimentos"
}, {
label: "Outros",
category: "Recebimentos"
}, {
label: "Fornecedores",
category: "Pagamentos"
}, {
label: "FSW",
category: "Pagamentos"
}, {
label: "Outros",
category: "Pagamentos"
}];
$("#procura").catcomplete({
delay: 0,
source: data
});
});
的jsfiddle here