【问题标题】:Kendo TreeView with remote datasource only populates the root elements具有远程数据源的 Kendo TreeView 仅填充根元素
【发布时间】:2015-01-20 11:09:31
【问题描述】:

我在使用远程数据源完全填充 Kendo TreeView 时遇到了困难,尽管使用本地数据源它可以正常工作。

简而言之,下面的第一个示例使用本地数据源。这一切都很完美:

// local datasource, works perfectly
var local = new kendo.data.HierarchicalDataSource({
    data: [
        {
            "DeviceGroupId": 1,
            "DeviceGroupName": "Superdeluxe Devices",
            "Devices": [
                {
                    "Id": 1000,
                    "Name": "My First Device"
                },
                {
                    "Id": 1001,
                    "Name": "My Second Device"
                }
            ]
        }
    ],
    schema: {
        model: {
            children: "Devices"
        }
    }
});

// initialize - this works!
$("#list-of-devices").kendoTreeView({
    dataSource: local,
    dataTextField: ["DeviceGroupName", "Name"],
    loadOnDemand: false
});

同样,上面的示例运行良好。现在,下面的第二个示例没有:它仅填充树视图的根元素(“Superdeluxe 设备”)。它完全忽略了孩子们。

// remote datasource
var remote = new kendo.data.HierarchicalDataSource({
    transport: {
        read: {
            url: "/api/devices/list", // <-- confirmed this works
            dataType: "json",
            contentType: "application/json"
        },
        schema: {
            model: {
                children: "Devices"
            }
        }
    }
});

// initialize
$("#list-of-devices").kendoTreeView({
    dataSource: remote, // the issue: only shows top level nodes
    dataTextField: ["DeviceGroupName", "Name"],
    loadOnDemand: false
});

因此,第二个示例中的问题是仅显示顶级节点,没有任何扩展选项。

我研究了以下内容:

总之,我似乎无法弄清楚为什么本地变体可以完美运行 - 并且遥控器没有显示孩子。有什么建议吗?

【问题讨论】:

    标签: javascript kendo-ui kendo-treeview


    【解决方案1】:

    问题出在您的远程数据源定义中,您将schema.model 定义为传输的一部分,但事实并非如此。应该是:

    var remote = new kendo.data.HierarchicalDataSource({
        transport: {
            read: {
                url: "list.json",
                dataType: "json",
                contentType: "application/json"
            }
        },
        schema: {
            model: {
                children: "Devices"
            }
        }
    });
    

    schematransport 处于同一级别。

    【讨论】:

    • 啊,我完全瞎了眼。这确实是问题所在。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-08-08
    • 1970-01-01
    • 1970-01-01
    • 2022-08-03
    • 1970-01-01
    相关资源
    最近更新 更多