var jsons={"my":[{"name":"ssh","age":"18"},{"name":"snow","age":"19"}]};
$(function() {

$( "#city" ).autocomplete({
source: function( request, response ) {
$.ajax({
url: "",
dataType: "json",
data: jsons,
success: function( data ) {
response( $.map(data.my, function( item ) {
return {
label: item.name + (item.name ? ", " + item.name : "") + ", " + item.age,
value: item.name
}
}))
}
});
},
minLength: 1 });
});
是不是有点新,我怎么整不明白,网上的列子都有点老,有些参数,方法啥的对不上,谁能帮忙看下
我本来做的AJAX调个ACTION,返回的就是像jsons这个变量一样的值,返回到是返回了,就是显示不出来?
好像response里面没写对,不知道是不是?

解决方案 »

  1.   

    response( $.map(data.my, function( item ) {
                                return {
                                    label: item.name + (item.name ? ", " + item.name : "") + ", " + item.age,
                                    value: item.name
                                }
                            }))response是你写的一个回调函数