我想查看自动完成后自动完成的数据:source" get"请求已经完成。
我的来源是字符串:" /jsonplaylist.json"。我可以通过查看Firebug控制台看到Get请求响应:
["01-List","02-List","03-List","04-List","05-List","06-List","07-List","08-List","08-List","09-List","10-List","playlist01 - updated","playlist02","playlist03"]
但是自动完成有哪些数据?我相信自动完成功能会创建一个新的数据结构,其中包含"标签"和"价值"。反正有没有看到整个数据结构?
我的自动填充功能目前如下所示:
$( "#birds" ).autocomplete({
source: "/jsonplaylist.json",
minLength: 1,
select: function( event, ui ) {
console.log( ui.item ? "Selected: " + ui.item.value : "Nothing selected, input was " + this.value );
return false;
}
});
我在Rails 4应用程序中使用它并且它正常工作。我想添加一个" id"对于" get"中的值请求,当我这样做时,一切都停止工作(我的获取响应是一个数组数组),即使我添加一个_renderItem - 我确定问题是数据,但我不知道如何看到自动填充正在使用的数据。
答案 0 :(得分:1)
知道了。我误解了自动完成响应事件。
http://api.jqueryui.com/autocomplete/#event-response
$( "#birds" ).autocomplete({
source: "/jsonplaylist.json",
minLength: 0,
select: function( event, ui ) {
console.log(event);
document.getElementById("birds").value = ui.item.value;
document.getElementById("birdsID").value = ui.item.id;
return false;
},
response: function(event, ui) { console.log(ui); }
}); // this ends the .data(ui-autocomplete)
搜索完成后,在显示菜单之前触发。