Jquery ui 自动完成让我发疯
我有一个
我在我的 .ready
函数中
$("#txtCustome2r").autocomplete({
source: "itemcomplete.asp",
minLength: 2,
select: function( event, ui ) {
log( ui.item ?
"Selected: " + ui.item.value + " aka " + ui.item.id :
"Nothing selected, input was " + this.value );
}
});
自动完成返回有效的 json
[ { "id': "4", "label": "Kathi ", "value": "Kathi "}, { "id': "6", "label": "Kathleen ", "value": "Kathleen "}]
,并且下拉列表中没有显示任何内容。非常感谢任何帮助!
谢谢!
I have a <input id="txtCustome2r" />
I have in my .ready
function
$("#txtCustome2r").autocomplete({
source: "itemcomplete.asp",
minLength: 2,
select: function( event, ui ) {
log( ui.item ?
"Selected: " + ui.item.value + " aka " + ui.item.id :
"Nothing selected, input was " + this.value );
}
});
the auto complete return valid json
[ { "id': "4", "label": "Kathi ", "value": "Kathi "}, { "id': "6", "label": "Kathleen ", "value": "Kathleen "}]
and nothing shows up in the drop down. Any help is greatly appreciated!
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
单引号不是有效的 JSON。您需要用双引号将键名和字符串值引起来:
如果您想检查 JSON 响应的有效性,可以使用 JSONLint。
Single quotes are not valid JSON. You'll need to surround your key names and string values with double quotes:
If you want to check your JSON response for validity, you can use JSONLint.
如果按照 @Mark Bell 的解决方案中所述验证格式后仍然遇到问题,请尝试将
dataType: 'json'
传递给自动完成函数调用。If you are still having problems after verifying your format as mentioned in @Mark Bell's solution, try passing in
dataType: 'json'
to the autocomplete function call.这可能有点棘手。我喜欢将源代码变成一个函数,这样我就可以有更多的控制权。注意 toString 的覆盖:
This can be a little tricky. I like making the source a function so I can have more control. Notice the override on toString: