JQuery自动完成选择未定义错误
JQuery Autocomplete select undefined error
几个小时以来我一直在绞尽脑汁,似乎不知道为什么出错了。
当我调用以下代码时:
$(document).ready(function () {
$("#searchBox").autocomplete({
select: function (event, ui) {
$("#searchBox").attr("readonly", true);
//this is where if i call alert(ui.long) I get undefiend
$("#CoorLong").val(ui.long);
$("CoorLat").val(ui.lat);
print_r(ui);
},
source: function (request, response) {
$.ajax({
url: "http://dev.virtualearth.net/REST/v1/Locations",
dataType: "jsonp",
data: {
key: "bingKey",
q: request.term
},
jsonp: "jsonp",
success: function (data) {
var result = data.resourceSets[0];
if (result) {
if (result.estimatedTotal > 0) {
response($.map(result.resources, function (item) {
return {
data: item,
label: item.name + '[' + item.point.coordinates[0] + ' ' + item.point.coordinates[1] + ']' + ' (' + item.address.countryRegion + ')',
value: item.name,
long: item.point.coordinates[0],
lat: item.point.coordinates[1]
}
}));
}
}
}
});
},
minLength: 1
});
});
正如我在selec: function(event, ui)中所说的,当我调用ui时。项或ui。值或ui。我总是得到undefined
我实现了print_r()来检查内容,我确实得到了这个:
- (数据)=祝辞对象
- [__type] =祝辞;地点:http://schemas.microsoft.com/search/local/ws/rest/v1
- [bbox] =祝辞对象
- [0] =祝辞48.83231728242932
- [1] =祝辞2.2598159619433122
- [2] =祝辞48.840042717570675
- [3] =祝辞2.275464038056688
- [名字]=祝辞多尔'Issy-les-Moulineaux,75015巴黎
- [point] =>object
- [type] => point
- [0] =>object
- [1] =>2.26764
所以我不明白为什么它是undefined
谢谢你
来自文档:
ui.item refers to the selected item.
所以我认为你想要ui.item.long
而不是ui.long
相关文章:
- 通过属性名称选择每个td,然后给出'未定义'用于属性值
- 浏览并选择用户硬盘驱动器中的文件在IE中未定义
- jQuery:使用正确的选择器在对象上未定义
- JSON检索中选择框的额外未定义选项
- 未定义访问具有对象属性的jquery选择器
- 未定义的引用-jQuery选择器与JavaScript变量
- 来自动态生成的选择的值是“未定义的”
- 以 $_POST 为单位的未定义索引,具有多项选择
- 选择未定义,jQuery UI
- AngularJS Bootstrap UI,将数据传递到模态的问题.已选择卡未定义
- “未捕获的类型错误:无法调用未定义的方法'indexOf'”时选择jqgrid行
- <选择>的获取值显示为未定义.(棱角.js)
- 尝试选择哪个单选按钮以及何时通过代码放置它返回未定义
- 未定义的 ajax post with for 循环和字符串选择器
- 表单提交<选择>为未定义
- 反应选择未捕获类型错误:无法读取未定义的属性“值”
- 日期时间选择器引导程序获取值并将其用作输入未定义的错误
- 获取类型错误:e 未定义与 js 插件日期时间选择器
- JQuery自动完成选择未定义错误
- Angular $watch命令选择未定义的变量