select2 jquery: 在createTag上,指定新标签的值

select2 jquery: On createTag, specify the value of the new tag

有没有办法自定义新标签的值?例如我想创建这样的东西: <option value="myCustomValue">The New Created Tag</option>

我正在尝试这样做,但没有成功,而且我在文档中找不到关于此的内容:

        createTag: function (params) {
            var term = $.trim(params.term);

            if (term === '') {
                return null;
            }

            return {
                id: term,
                text: term,
                newTag: true, // add additional parameters,
                value: "myCustomValue"
            }
        }

Select2 可以根据用户在搜索框中输入的文本动态创建新选项。此功能称为 "tagging"。要启用标记,请将标记选项设置为 true。

$('#example').select2({  
    tags: true
});

试试这个https://jsfiddle.net/qrdvjzyp/

根据文档,方法是这样的:

createTag: function(params) { return { id: "myCustomValue", text: params.term }}