javascript 选择 js 自动完成似乎不起作用
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/19248171/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
selectize js autocomplete doesnt seem to work
提问by Athanatos
Please see the following example fiddle :
请参阅以下示例小提琴:
Although I can select the option from the dropdown, typing doesnt autocomplete. I would expect that when you type B or A you should get the recommendation for banana, apple. Only when of my items in the list is not an existing item it should ask me to add it...
虽然我可以从下拉列表中选择该选项,但输入不会自动完成。我希望当你输入 B 或 A 时,你应该得到香蕉、苹果的推荐。只有当我的列表中的项目不是现有项目时,它才应该要求我添加它...
var data = [ "banana", "apple", "orange" ]; var items = data.map(function(x) { return { item: x }; });
var data = [“香蕉”,“苹果”,“橙色”];var items = data.map(function(x) { return { item: x }; });
$('#input-tags').selectize({
delimiter: ',',
persist: false,
maxItems: 1,
create:true,
options: items,
labelField: "item",
valueField: "item"
});
Any ideas?
有任何想法吗?
Note the same scenario seems to be working with predefined values : Fiddle
请注意,相同的场景似乎使用预定义的值: Fiddle
回答by Snowburnt
You need to add a
你需要添加一个
searchField: "item"
to the selectize declaration
到选择声明
here's the fixed fiddle: http://jsfiddle.net/wh6Nx/
这是固定的小提琴:http: //jsfiddle.net/wh6Nx/
to add items you need a
要添加您需要的项目
create: function(input) {
return {
value: input,
text: input
}
}
fiddle with both: http://jsfiddle.net/2ZrEu/
摆弄两者:http: //jsfiddle.net/2ZrEu/