在json中得到响应,但这不会解析json响应。我做错了什么?我不能在doc
http://docs.jquery.com/Plugins/Autocomplete上找到任何东西
$("#users-allowed").autocomplete("/people/following.json",{ width: 320,//max: 4,highlight: false,scroll: true,scrollHeight: 300,formatItem: function(response,i,max) { console.log(response); console.log(response['items']); console.log(response.items); return i + "/" + max + ": \"" + response.status_code + "\" [" + response.status_description + "]"; //return "<img src='images/" + value + "'/> " + value.split(".")[0]; },formatResult: function(response) { //return value.split(".")[0]; return response.status_description; } });
解决方法
$("#users-allowed").autocomplete("/people/following.json",dataType: 'json',parse: function(data) { var array = new Array(); for(var i=0;i<data.items.length;i++) { array[array.length] = { data: data.items[i],value: data.items[i],result: data.items[i].username }; } return array; },formatItem: function(row) { var name = ''; if (row.first_name && row.last_name) name = '('+row.first_name+','+row.last_name+')'; else if (row.first_name) name = '('+row.first_name+')'; else if (row.last_name) name = '('+row.last_name+')'; return row.username+' '+name; } });
检查dataType和解析选项。