tokeninput jquery插件 - preventDuplicates不工作

Bil*_*ill 8 javascript jquery

我正在使用jquery插件Tokeninput.我需要阻止用户输入重复值,Js代码如下:

$(document).ready(function () {
    // Configure Tags
    $('#Tags').tokenInput(tagSource(), 
    {
        prePopulate: selectedTags(),
        theme: "facebook",
        propertyToSearch: "Code",
        preventDuplicates: true
     });

    function tagSource() {
        var data = [];
        @if (Model.SourceTags != null && Model.SourceTags.Count() > 0) {
            <text>
                data = @(Html.Raw(Model.SourceTags));
            </text>
        }
        return data;
    }

    function selectedTags() {
        var selectedData = [];
         @if (Model.SelectedTags != null && Model.SelectedTags.Count() > 0) {
            <text>
                selectedData = @(Html.Raw(Model.SelectedTags));
            </text>
        }
        return selectedData;
    }
});
Run Code Online (Sandbox Code Playgroud)

当我再次选择相同的项目时,"输入"字段中的现有项目将突出显示,并且不会添加任何内容.

此外,当我选择不同的项目时,第一个项目会突出显示,并且不会添加任何内容.

任何的想法?

谢谢

小智 8

如果你还有这个问题,我想我可能知道发生了什么.TokenInput假定数据对象的"id"属性拼写为"id"(注意小写).如果你的id属性拼写不同,你所描述的将会发生.供您参考,这发生在add_token函数中(v1.6.0 tokeninput.js中js文件中的第495行).