我想在插入令牌时从源数组中删除令牌。我有这个:
$('#tokenfield').on('tokenfield:createdtoken', function (event) {
console.log("teste");
var selectedToken = event.attrs.value;
var existingTokens = $('#tokenfield').tokenfield('getTokens', false);
var newTokens = removeFromArray(existingTokens, selectedToken);
$('#tokenfield').data('bs.tokenfield').$input.autocomplete(
{ source: newTokens });
});
function removeFromArray(existing, selected) {
for (let i = 0; i < existing.length; i++) {
if (existing[i].value == selected) {
existing.splice(i, 1);
}
}
return existing;
}
但是,打印“ getTokens”的结果,它给了我一个空数组。
有人知道我该怎么办吗?
谢谢!