在kendo自动完成小部件向服务发送ajax请求之前,我无法更改网址 在更改参数map中的url之前,它已经先加载.Kendo会自动添加 搜索字符串到URL。 当我按下一个键时,我可以更改URL,但数据是绑定到自动完成的prev请求 数据。 任何人都可以建议我找到更改网址的正确位置。
$('#AddressSearchTerm').kendoAutoComplete({
dataTextField:"Text"
filter: "contains",
minLength: 2,
delay: 700,
dataSource: {
type: "json",
serverFiltering: true,
transport: {
read: "http://services.postcodeanywhere.co.uk/CapturePlus/Interactive/Find/v2.00/json3.ws?SearchTerm=a&LastId=&SearchFor=Everything&Country=GBR&LanguagePreference=EN",
type: "POST",
dataType: "jsonp",
parameterMap: function (options, operation) {
var p = $('#AddressSearchTerm').data("kendoAutoComplete");
var serviceurl1 = "http://services.postcodeanywhere.co.uk/CapturePlus/Interactive/Find/v2.00/json3.ws?SearchTerm=" + options.filter.filters[0].value + "&LastId=&SearchFor=Everything&Country=GBR&LanguagePreference=EN";
p.dataSource.transport.options.read.url = serviceurl1;
}
},
schema:{data:"Items"}
}
});
答案 0 :(得分:2)
您应该在data
定义中使用transport.read
,而不是在paramMap中定义变量参数。文件说:
所以,你的代码应该是这样的:
$('#AddressSearchTerm').kendoAutoComplete({
dataTextField: "Text",
filter: "contains",
minLength: 2,
delay: 700,
dataSource: new kendo.data.DataSource({
type: "json",
serverFiltering: true,
transport: {
read: {
url: "http://services.postcodeanywhere.co.uk/CapturePlus/Interactive/Find/v2.00/json3.ws?SearchTerm=a&LastId=&Country=GBR&LanguagePreference=EN",
data: function (options) {
console.log("value", options.filter.filters[0].value);
return "SearchTerm=" + options.filter.filters[0].value
}
},
type: "POST",
dataType: "jsonp",
},
schema: {data: "Items"}
})
});