1

我无法在 kendo 自动完成小部件向服务发送 ajax 请求之前更改 url 在我更改参数映射中的 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"}
             }
     });
4

1 回答 1

2

Instead of defining the variable parameters in paramMap, you should use data in transport.read definition. The documentations says:

enter image description here

So, your code should be something like:

$('#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"}
    })
});
于 2014-11-13T10:20:19.977 回答