在结果中映射一个 json 以 jquery 自动完成
Mapping a json with $ in result for jquery autocomplete
>我试图让一些自动完成工作。我有这个 URL,我应该从中读取我的 JSON:
http://openscan.addi.dk/2.0/?action=openScan&field=phrase.title&lower=hest&limit=10&outputType=json
当我收到结果时,我尝试将其映射到我的 jquery 自动完成中,我使用以下 jquery:
<script type="text/javascript">
$(function () {
function log(message) {
$("<div/>").text(message).prependTo("#log");
$("#log").scrollTop(0);
}
$("#search").autocomplete({
source: function (request, response) {
$.ajax({
url: "http://openscan.addi.dk/2.0/?action=openScan&field=phrase.title&lower=hest&limit=10&outputType=json",
dataType: "jsonp",
success: function (data) {
response($.map(data.scanResponse.term, function (item) {
return {
label: item.name+' ( '+item.hitCount+')',
value: item.name
}
}));
}
});
},
minLength: 2,
select: function (event, ui) {
log(ui.item ?
"Selected: " + ui.item.label :
"Nothing selected, input was " + this.value);
},
open: function () {
$(this).removeClass("ui-corner-all").addClass("ui-corner-top");
},
close: function () {
$(this).removeClass("ui-corner-top").addClass("ui-corner-all");
}
});
});
</script>
<h2>
Demo of autocomplete using OpenScan
</h2>
Start typing below.<br />
<input id="search" />
我的问题是结果不像我以前见过的有限数量的 JSON,它包含属性的 $ 和 @,我如何索引它们?
编辑已更改 data.scanResponse to data.scanResponse.term
不确定要显示的确切值是什么,但您可以使用数组语法访问属性,如下所示:
label: item.name["@"]+' ( '+item.hitCount["$"]+')'
相关文章:
- SharePoint 2010 Jquery/JSON Rest Multiple OR语句-如何
- AJAX jquery json将数组发送到php
- JavaScript/jQuery JSON数组问题-值为未定义
- JQuery JSON 数据未显示
- 如何使用onLoad加载jQuery JSON.从Zipcode On Form获取城市和州
- TypeError: 使用 Jquery JSON 获取数据时无效的 'in' 操作数 obj
- JQUERY JSON返回未定义
- jQuery JSON flickr提要返回false不工作
- 遍历jQuery JSON对象数组
- Jquery json:未捕获类型错误:无法读取属性'xx'的未定义
- Jquery Json Api
- jquery json 返回添加两个数字的数据
- 使用jquery-json-ajax.php删除整行
- 意外的PHP/jQuery/JSON交互差异
- jquery JSON 数组作为本地存储项
- 如何使用jQuery/JSON限制字符数
- Javascript中应用的jQuery JSON数据库变量
- jquery json post不起作用
- 将输入字段文本放入变量中并将其用于 jquery JSON get 请求
- 第二个 Jquery json 在第一个 Jquery 完成之前被解雇