1
我的自动完成输入字段不起作用,我找不到原因。我正在使用外部JSON文件,如下所示:jQuery UI自动完成与json文件
{
"nodes": [
{"id": "nt", "data": {
"class": "date",
"label": "Expositions New Tendencies",
"tooltip": "New Tendencies Exhibition",
"content": "Ceci est une visualisation de donnée concernant les différentes expositions sous le nom de 'New Tendencies', et regroupe les différents artistes, et leurs oeuvres. Pour parcourir la visualisation, cliquez sur les différents noeuds !",
"graphicFillColor": "#fff",
"graphicSize": 80,
"labelFontSize": 18,
"labelFontWeight": "regular",
"labelPosition": "right"
}}],
"edges": [
{"source": "nt1", "target": "AdrianMarc"}
]}
为了清楚起见,我选择了多维数组。下面是自动完成的
$(function() {
$('#recherche').autocomplete({
source: function (request, response) {
$.ajax({
url: "feature-tour.json",
dataType: 'json',
data: request,
success: function(data) {
response($.map(data, function(item) {
console.log(item.nodes.id);
return(item.nodes.id)
}));
}
});
},
minLength: 0
});
});
和HTML输入我的JavaScript文件:
<input type="text" id="recherche" placeholder="→ Rechercher un artiste"/>
我想显示自动完成输入内部节点的标签,如果有人可以帮助我进入到节点的标签。谢谢 !
谢谢你的帮助@nikoshr。但是我还有一个问题,是否必须将我的JSON文件的内容放入'var'或不是?因为如果我的autocomple的'source'是一个将过滤请求的函数,我不能再使用我的JSON文件了? – suniz 2015-04-03 11:48:17
我不确定我是否理解你的问题,你的文件内容可以通过'data'参数在'success'回调中获得。如果您指的是我在Fiddle中设置的方式,那只是一个演示,您不必在应用程序中复制文件的内容。基本上,只需更换你的回调,你应该没问题。 – nikoshr 2015-04-03 12:03:34
我问了我的问题后,我想出了它。再次感谢您的帮助。 – suniz 2015-04-03 12:28:19