[英]jQuery UI Autocomplete Responce Data
I am having some trouble accessing the JSON data provided by a script for an autocomplete box, and was wondering if anybody could help. 我在访问由自动完成框的脚本提供的JSON数据时遇到了一些麻烦,并且想知道是否有人可以提供帮助。
This is the Javascirpt code which deals with the autocomplete box: 这是处理自动完成框的Javascirpt代码:
$(function() {
$("#student_search").autocomplete({
source: "functions/find_student.php",
delay: 100,
minLength: 1,
select: function(event, ui) {
student_result = ui;
$('#student_search').val(student_result[0].label);
highlightStudent(student_result.label, student_result.value.id, student_result.value.house);
}
});
});
And an example of the response is: 响应的示例是:
[{"label":"larry winkles","value":{"id":1,"house":"s"}}]
I am struggling to find out how to access that data when it gets sent back to the success part of the autocomplete code. 我正在努力寻找如何在将数据发送回自动完成代码的成功部分时访问该数据。 Specifically when I click on the name, the error I get is:
具体来说,当我单击名称时,出现的错误是:
Uncaught TypeError: Cannot read property 'label' of undefined
Thanks for any help. 谢谢你的帮助。
Alex 亚历克斯
I have a doubt about the nature of the ui variable, may be you can check it by using console.info(ui)
if you were on Firefox. 我对ui变量的性质有疑问,如果您使用的是Firefox,也许可以通过使用
console.info(ui)
进行检查。
I suppose that the problem is in line : 我想问题就在这里:
highlightStudent(student_result.label, student_result.value.id, student_result.value.house);
replace : 替换:
student_result
by : 创建人:
student_result[0]
Have you tried like this : 您是否尝试过像这样:
select: function(event, ui) {
var label = ui.item.label;
var value = ui.item.value;
}
Let me know for any concerns. 如有任何疑问,请通知我。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.