我希望使用Kendo界面将自动填充添加到我的网站https://www.headlineintime.com/,并希望将其连接到Google Suggest,因为新闻搜索框会在网络上显示相关内容。有什么想法应该如何连线?我试过用这个:
$('#search').kendoAutoComplete({
minLength: 3,
filter: "startswith",
placeholder: "Search ...",
suggest: true,
select: function (e) {
$('#btnSearch').trigger('click');
},
dataSource: new kendo.data.DataSource({
serverFiltering: true,
transport: {
read: {
url: "https://suggestqueries.google.com/complete/search?client=firefox",
data: onAdditionalData,
type: "get",
dataType: "jsonp",
}
},
})
但这似乎不起作用。问题是它没有正确显示Google建议的项目:
看着Fiddler从谷歌回来的JSON看起来像:
任何建议(没有双关语意)?谢谢你的帮助!
-Mike
答案 0 :(得分:0)
我找到了我所缺少的东西。我需要架构设置让parse属性指向结果的第二个元素,即列表。以下是自动填充的完整代码:
$('#search').kendoAutoComplete({
minLength: 3,
filter: "startswith",
placeholder: "Search ...",
suggest: true,
select: function (e) {
$('#btnSearch').trigger('click');
},
dataSource: new kendo.data.DataSource({
serverFiltering: true,
transport: {
read: {
url: "https://suggestqueries.google.com/complete/search?client=firefox",
data: onAdditionalData,
type: "get",
dataType: "jsonp",
}
},
schema: {
parse: function(data) {
return data[1];
}
}
})
});
您可以在https://www.headlineintime.com看到它正常工作: