javascript tag-it 允许的标签

javascript tag-it allowed tags

我需要允许用户 select 只允许在 tagSource 中使用标签。

目前我有:

var sampleTags = ['c++', 'java', 'php', 'coldfusion', 'javascript', 'asp', 'ruby', 'python', 'c', 'scala', 'groovy', 'haskell', 'perl', 'erlang', 'apl', 'cobol', 'go', 'lua'];
$("#myTags").tagit({
    tagSource: sampleTags 
});

tag-it in GitHub

Tag-it! Usage Examples

你能帮我解决这个问题吗?

检查它是否有效

 var sampleTags = ['c++', 'java', 'php', 'coldfusion', 'javascript', 'asp', 'ruby', 'python', 'c', 'scala', 'groovy', 'haskell', 'perl', 'erlang', 'apl', 'cobol', 'go', 'lua'];
    $("#myTags").tagit({
        availableTags: sampleTags,
         afterTagAdded: function (event, ui) {
        if ($.inArray(ui.tagLabel, sampleTags) == -1) {
            $("#myTags").tagit("removeTagByLabel", ui.tagLabel);
        }
    }
    });