【发布时间】:2014-02-27 02:02:15
【问题描述】:
我正在使用带有类别的 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
【问题讨论】:
标签: javascript jquery jquery-autocomplete