我试图将这个Tagify脚本从一个数组转换成一个字符串。问题是,Tagify的所有输出都包含值和逗号,到目前为止,我还无法将这些数组转换为一个很好的字符串。我该怎么做?
我使用脚本创建标记,然后在搜索(GET)中使用。这是在URL ?query=[{"value"%3A"bee"}]而不是?query=bee中得到的。
var input = document.querySelector('input[name=query]'),
// init Tagify script on the above inputs
tagify = new Tagify(input, {
// after 2 characters typed, all matching values from this list will be suggested in a dropdown
whitelist: ["Door", "Cat", "Mouse", "Chicken", "Duck"]
})发布于 2020-09-03 18:37:51
若要更改格式,假设标记没有逗号,则可以使用originalInputValueFormat https://github.com/yairEO/tagify#settings。
var tagify = new Tagify(input, {
// after 2 characters typed, all matching values from this list will be suggested in a dropdown
whitelist: ["Door", "Cat", "Mouse", "Chicken", "Duck"],
originalInputValueFormat: valuesArr => valuesArr.map(item => item.value).join(', ')
})输出:“猫,老鼠”
https://stackoverflow.com/questions/58298827
复制相似问题