Kndo TreeView LoadOnDemand没有命中服务器

时间:2016-10-24 06:57:50

标签: kendo-ui kendo-treeview

对于我的剑道树视图,我将按需加载设置为true,但是没有按服务器加载子项,因为为数据源模型设置了'children'属性,即使它是空的。

homogeneous = new kendo.data.HierarchicalDataSource({
         transport: {
            read: {
                type: 'POST',
                contentType: "application/json; charset=utf-8",
                url: obj.DataSourcesURL,
                dataType: "json"
            },
            parameterMap: function (options) {
                if (!options.Id) {
                    options.Id = null;

                }
                if (options.filter) {
                    options.Search = options.filter.filters[0].name;
                }
                else {
                    options.Search = '';

                }
                return JSON.stringify(options);
            }
        },
        schema: {
            data: "d",
            errors: function (response) {
                console.log(response);
                console.log("errors");
            },
            model: {
                hasChildren: "hasChild",
                children:'items',
                id: "Id"
            }
        }
    });

树视图代码是

$treeView.kendoTreeView({
        dataTextField: 'Description',
        checkboxes: {
            checkChildren: true
        },
        dataSource: homogeneous,
        loadOnDemand: loadOnDemand,
        check: function () {
            var checkedNodes = [];
            var treeView = $treeView.data("kendoTreeView");

            getCheckedNodes(treeView.dataSource.view(), checkedNodes);
            setMessage(checkedNodes.length);
        },
        dataBound: function (e) {
            if (e !== undefined)
                resetCheckedNodes(e.sender.dataItems());
        },
        messages: {
            loading: "Laden..."
        },
        expand: function (e) {
            var dataItem = this.dataItem(e.node);

        }
    });

1 个答案:

答案 0 :(得分:0)

尝试在架构中设置hasChildren

schema: {
        data: "d",
        errors: function (response) {
            console.log(response);
            console.log("errors");
        },
        model: {
            hasChildren: function(e) {
                    return e.items && e.items.length;
                },
            children:'items',
            id: "Id"
        }
    }

而且从您的问题来看,我不确定您是否获得任何数据,或者只有Children数据未被返回。也许您还可以展示您的数据结构的样子。