Bas*_*sit 20 jquery json autocomplete response
即时通讯在json中获得响应,但这不会解析json的响应.什么mi做错了?我无法在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;
}
});
Run Code Online (Sandbox Code Playgroud)
Bas*_*sit 33
$("#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;
}
});
Run Code Online (Sandbox Code Playgroud)
检查dataType和parse选项.
我想你只需要输入一个dataType选项,我记得你准备好了,你可以使用$.ajax自动完成器中的任何选项:
$("#users-allowed").autocomplete("/people/following.json", {
dataType: "json",
...
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
72770 次 |
| 最近记录: |