【发布时间】:2014-02-13 09:24:02
【问题描述】:
我正在尝试实现一个标记输入,除了我想限制用户只能选择 自动完成框中的值。 我尝试使用源 json 覆盖 beforeTagAdded 事件并检查标签是否存在 在源属性中,但没有运气。
这里是代码,见 beforeTagAdded 函数。
$(document).ready(function () {
var itemId;
var theTags = $('#msg_to');
theTags.tagit({
autocomplete: {
source: [{ id: "1", value: 'David'}, { id: "2", value: 'John' }],
minLength: 0,
select: function (event, ui) {
itemId = ui.item.id;
theTags.tagit("createTag", ui.item.value);
}
},
showAutocompleteOnFocus: true,
afterTagAdded: function (event, ui) {
if (itemId) {
$(ui.tag).find('input').attr('name', "tag[\'" + itemId + "']['" + ui.tagLabel + "']");
itemId = null;
}
},
beforeTagAdded: function (event, ui) {
var id = ui.autocomplete.source; // not working
// what to do next?
}
})
});
</script>
提前致谢
【问题讨论】: