我正在使用Horsey plugin为我的文本输入创建自动完成功能。我正在使用键/值对(第三个示例 here ),并且我想发布键值(我的应用程序中的 id),而不是我的搜索的文本值。
horsey(document.querySelector('#search_field'), {
source: [{ list: [
{ value: 'banana', text: 'Bananas from Amazon Rainforest' },
{ value: 'apple', text: 'Red apples from New Zealand' },
{ value: 'orange', text: 'Oranges from Moscow' },
{ value: 'lemon', text: 'Juicy lemons from the rich Amalfitan Coast' }
]}],
getText: 'text',
getValue: 'value'
});
所以我知道我必须从某个地方调用 getValue 函数,但我不知道如何调用。
最佳答案
您可以使用插入标签时运行的 predictNextSearch(info)。
horsey(document.querySelector('#search_field'), {
source: [{ list: [
{ value: 'banana', text: 'Bananas from Amazon Rainforest' },
{ value: 'apple', text: 'Red apples from New Zealand' },
{ value: 'orange', text: 'Oranges from Moscow' },
{ value: 'lemon', text: 'Juicy lemons from the rich Amalfitan Coast' }
]}],
getText: 'text',
getValue: 'value',
predictNextSearch(info) {
//get the suggestion selected by the user
console.log(info.selection.value);
}
});
希望这有帮助!
关于javascript - 如何获取自动完成文本的值[使用Horsey插件],我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38990526/