【发布时间】:2012-03-07 20:22:42
【问题描述】:
我正在尝试将自定义值传递给自动完成,所以:
我的自定义工作值基于this question
使用像文档这样的默认来源:
$("#inpPesqCli").autocomplete({
source: "ajax/search.php",
minLength: 2,
autoFocus: true
});
firebug 返回此(示例):
[...
{ "id": "29083", "label": "SOME ONE 2", "value": "SOMEONE WITH LELE" },
{ "id": "19905", "label": "SOME ONE", "value": "SOMEONE WITH LALA"},
...]
工作完美,结果显现。
当我尝试设置一些自定义值时:
$("#inpPesqCli").autocomplete({
source: function( request, response ) {
$.ajax({
url: "ajax/search.php",
dataType: "jsonp",
data: {
featureClass: "P",
style: "full",
maxRows: 12,
name_startsWith: request.term
},
success: function( data ) {
response( $.map( data.geonames, function( item ) {
return {
label: item.name + (item.adminName1 ? ", " + item.adminName1 : "") + ", " + item.countryName,
value: item.name
}
}));
}
});
},
minLength: 2,
autoFocus: true
});
firebug 为我返回完全相同的数组结果:
[...
{ "id": "29083", "label": "SOME ONE 2", "value": "SOMEONE WITH LELE" },
{ "id": "19905", "label": "SOME ONE", "value": "SOMEONE WITH LALA"},
...]
但是,问题是,当我通过自定义计算时,结果的剂量会显示出来。
php:
$type = "C";
$q = strtolower($_GET["name_startsWith"]); // this i change: custom = name_startsWith / default = term
if (!$q) return;
$res = $p->SomeClass($codemp,$q,$type);
$items = array();
while(!$res->EOF){
$items[$res->fields["NOMCLI"]] = $res->fields["CODCLI"];
$res->MoveNext();
}
// below this, i have the php autocomplete default function, if u need, ask then i post.
不知道我错过了什么。
【问题讨论】:
标签: php jquery arrays autocomplete