admin管理员组文章数量:1404927
I try to create an autoplete field with jQuery autoplete widget, but it seems that does not work for some reason.
The code I use is the following:
HTML
<input type="text" id="specialties" />
JavaScript
var $specialties = [
{
id : 107,
name : 'Painting'
},
{
id : 158,
name : 'Reading'
}
];
var $specialty_text_field = $('#specialties');
$specialty_text_field.autoplete(
{
source : $specialties,
minLength : 3
}
);
And when I enter in the text field the text Pain
I am getting as a result the text No search results.
What can be wrong with this code ?
I try to create an autoplete field with jQuery autoplete widget, but it seems that does not work for some reason.
The code I use is the following:
HTML
<input type="text" id="specialties" />
JavaScript
var $specialties = [
{
id : 107,
name : 'Painting'
},
{
id : 158,
name : 'Reading'
}
];
var $specialty_text_field = $('#specialties');
$specialty_text_field.autoplete(
{
source : $specialties,
minLength : 3
}
);
And when I enter in the text field the text Pain
I am getting as a result the text No search results.
What can be wrong with this code ?
Share Improve this question edited Jul 26, 2014 at 11:18 KodeFor.Me asked Jul 26, 2014 at 11:06 KodeFor.MeKodeFor.Me 13.5k28 gold badges103 silver badges172 bronze badges 5- 1 any console errors??? – Kartikeya Khosla Commented Jul 26, 2014 at 11:07
- @KartikeyaKhosla no at all. My console is totally clear. – KodeFor.Me Commented Jul 26, 2014 at 11:09
- @NaveenThally This is what I try but I get a console error that I cannot figure out. Here is the fiddle URL (jsfiddle/ZQ9T3). If somebody can help to fix the issue please? – KodeFor.Me Commented Jul 26, 2014 at 11:11
-
You have both
#autoplete
and#specialties
, which should be? – Sergio Commented Jul 26, 2014 at 11:12 - your souce needs to ba an array cosisting of Strings. you are giving an array consisting of objects... – Pinoniq Commented Jul 26, 2014 at 11:12
1 Answer
Reset to default 6As it is clearly stated in the docs, your fields must be labeled label
and value
.
Array: An array can be used for local data. There are two supported formats:
An array of strings: [ "Choice1", "Choice2" ] An array of objects with label and value properties: [ { label: "Choice1", value: "value1" }, ... ]
EDIT : And as it has been pointed out, the input's id is autoplete, not specialties.
本文标签: javascriptjQuery autocomplete doesn39t work with key value pair arrayStack Overflow
版权声明:本文标题:javascript - jQuery autocomplete doesn't work with key value pair array - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744874826a2629853.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论