【发布时间】:2014-03-17 11:56:26
【问题描述】:
我正在数据库中搜索一些项目并得到一个 json 响应。
但我不知道,我的自动完成功能的哪一部分不起作用 当我制作 console.log(item) 时,我从 item 中得到了这个输出:
Array
(
[0] => Array
(
[objektnummer] => 14720
[anschrift1] => Frau
[anschrift2] => xxxx
[strasse] => Bucxxx
[plz] => 8xxx
[ort] => Pxxxx
[projektstatus] => 3
[erstellungsdatum] => 2014-03-16 12:15:12
[fertigstellungsdatum] => 2014-03-14
)
[1] => Array
(
[objektnummer] => 14778
[anschrift1] =>
[anschrift2] => MFH + TG
[strasse] => Gedxxx
[plz] => 8xxx
[ort] => Ascxxx
[projektstatus] => 1
[erstellungsdatum] => 2014-02-05 12:15:12
[fertigstellungsdatum] => 2014-01-02
)
)
我的错误在哪里?来自 php 搜索的响应是正确的。因此,带有 url 的 ajax 也可以正常工作
$( "#qObject" ).autocomplete({
source: function( request, response ){
$.ajax({
url: $( "#spanqObject" ).data( "url" )
}).success(function(item){
console.log(item);
response(function(item) {
return {
label: item.anschrift2,
value: item.anschrift2
}
});
}).error(function(){
console.log("Mist");
});
},
minLength: 2,
select: function( event, ui ) {
log( ui.item ?
"Selected: " + ui.item.anschrift2 + " aka " + ui.item.objektnummer :
"Nothing selected, input was " + this.value );
}
});
【问题讨论】:
-
如果可以的话,创建一个小提琴。
-
我不明白你的问题是什么。请更具体。
-
我没有得到包含搜索结果的列表
-
console.log 告诉你什么?
标签: jquery jquery-ui autocomplete