0
我想添加一个自动完成输入文本框,它将使用Pipedrive API检索数据。自动完成JSON数据使用jQuery
JSON响应我从Pipedrive得到如下: -
{
"success": true,
"data": [{
"id": 1671,
"title": "Queens Park Tyres deal"
}, {
"id": 1672,
"title": "Wildman Craft Lager deal"
}, {
"id": 1673,
"title": "General Store deal"
}, {
"id": 1674,
"title": "Deluxe Off Licence deal"
}, {
"id": 1675,
"title": "Ahmed Halal Bazaar deal"
}],
"additional_data": {
"pagination": {
"start": 0,
"limit": 5,
"more_items_in_collection": true,
"next_start": 5
}
}
}
基本上,我需要回到他们选择的价值的标题和编号。
此刻我的jQuery代码如下: -
$('#search-deal').autocomplete({
source: function (request, response) {
$.getJSON("https://api.pipedrive.com/v1/searchResults/field?term=deal&field_type=dealField&field_key=title&start=0&api_token=<my_token>", function (data) {
response($.map(data.title, function (value, key) {
return {
label: value,
value: key
};
}));
});
},
minLength: 2,
delay: 100
});
尝试是这样的:http://jsfiddle.net/DLLVw/ –