jQuery标记它只允许使用可用的标记

jQuery标记它只允许使用可用的标记,jquery,tag-it,Jquery,Tag It,我在脚本中使用jQuery: $("#user_autocomplete").tagit({ tagSource: function (request, response) { $.ajax({ data: { term: request.term }, type: "POST", url: "/site2/message/users.php",

我在脚本中使用jQuery:

$("#user_autocomplete").tagit({
    tagSource: function (request, response) {
        $.ajax({
            data: {
                term: request.term
            },
            type: "POST",
            url: "/site2/message/users.php",
            dataType: "json",
            success: function (data) {
                response($.map(data, function (item) {
                    return {
                        label: item,
                        value: item
                    }
                }));
            }
        });
    },
    tagLimit: 3,
    autocomplete: {
        delay: 0,
        minLength: 1
    },
});
在这种情况下,确认所有输入字段。但我只希望添加可用的字段。怎么做?

代表OP发布:

我正在使用beforeTagAdded函数我找到了答案:

        tagSource: function(request, response) 
        {
            $.ajax({
                data: { term:request.term },
                type: "POST",
                url:        "/site2/message/users.php",
                dataType:   "json",
                 success: function( data ) {
                     array = data;
                    response( $.map( data, function( item ) {

                        return {
                            label:item,
                            value: item
                        }
                        }));
                    }

            });
            },
        tagLimit :3,
        autocomplete: {delay: 0, minLength: 1},
        beforeTagAdded: function(event, ui) {
            if(array.indexOf(ui.tagLabel) == -1)
            {
                return false;
            }
            if(ui.tagLabel == "not found")
            {
                return false;
            }

        },

我可以通过在
createTag
函数顶部添加以下检查来实现这一点:

if (this.options.onlyAvailableTags && $.inArray(this._formatStr(value), this.options.availableTags) == -1) {
    return false;
}
然后在
标记中添加此选项
调用:

onlyAvailableTags: true

你能再解释一下吗?“仅可用字段”是什么意思?感谢您添加自己的解决方案。我把它移到了一个答案;如果你希望在将来为自己的问题提供一个解决方案,最好是这样自我回答。@ KkistoRi:我只是代表OP发布的——如果你喜欢的话,不妨考虑一下原来的帖子。谢谢你分享这一段快乐(做了原创的帖子)!你应该考虑对原始项目提出一个请求: