Kendo UI AutoComplete 数据源传输仅读取一次 [英] Kendo UI AutoComplete datasource transport reads only once

查看:13
本文介绍了Kendo UI AutoComplete 数据源传输仅读取一次的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对 Kendo UI AutoComplete 组件非常着迷.我使用自己的函数通过 jQuery 访问数据,因此我必须将 AutoComplete dataSource.transport.read 设置为函数.代码是这样的.

I'm becoming crazy with Kendo UI AutoComplete component. I'm using my own functions to access data with jQuery, so I have to set the AutoComplete dataSource.transport.read as a function. The code is something like this.

minLengthAtocomplete = 3;

$('#autocomplete').kendoAutoComplete({
    minLength : 3,
    filter : "contains",
    dataValueField : "key",
    dataTextField : "value",
    dataSource : new kendo.data.DataSource({
        transport : {
            read : _OnTransportRead
        },
        schema : {
            /* object schema */
        }
    })
});

function _OnTransportRead(e) {
    var text = $.trim(e.data.filter.filters[0].value);

    if (text && text.length >= minLengthAtocomplete) {
        _GetUsers(
            text,
            function onSuccess(data) {
                var users = [];
                 /* sets users with info in data */
                e.success(users);
            },
            function onError(error) {
                /* stuff with error */
            }
        );
    }
}

function _GetUsers(userName, onSuccess, onError) {
    /* Ajax to get users from DB */
}

此代码运行良好,但 dataSource.transport.read 仅被调用一次.我使用文本 'michae' 进行第一次搜索,AutoComplete 组件按预期运行它的 dataSource.transport.read.然后,我再添加一个字母来搜索 'michael',并且 dataSource.transport.read 不再被调用.好郁闷!

This code runs perfectly, but dataSource.transport.read is called only the once. I do a first search with the text 'michae' and AutoComplete component runs its dataSource.transport.read as expected. Then, I add a one more letter to search for 'michael', and dataSource.transport.read is never called again. Is so frustrating!

我尝试使用自动同步数据源属性,手动同步数据源,在自动完成数据绑定上设置新的数据源对象,但没有成功.

I tried using autoSync dataSource property, manual dataSource Sync, set new dataSource objects on AutoComplete dataBound, but no luck.

我做错了什么?我忘记了什么?

What am I doing wrong? What am I forgetting?

提前致谢.

推荐答案

您应该启用 serverFiltering 为了让数据源每次都发出请求.

You should enable serverFiltering in order for the data source to make requests every time.

$('#autocomplete').kendoAutoComplete({
    minLength : 3,
    filter : "contains",
    dataValueField : "key",
    dataTextField : "value",
    dataSource : new kendo.data.DataSource({,
        serverFiltering: true, 
        transport : {
            read : _OnTransportRead
        },
        schema : {
            /* object schema */
        }
    })
});

这篇关于Kendo UI AutoComplete 数据源传输仅读取一次的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆