gpt4 book ai didi

jquery 自动完成与 json 响应

转载 作者:行者123 更新时间:2023-12-03 21:45:54 25 4
gpt4 key购买 nike

我收到 json 响应,但这不会解析 json 响应。我做错了什么?我在文档 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", {
width: 320,
dataType: 'json',
highlight: false,
scroll: true,
scrollHeight: 300,
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;
}
});

检查数据类型和解析选项。

关于jquery 自动完成与 json 响应,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1592048/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com