Kendo treeview HierarchicalDataSource不显示子节点

时间:2016-03-23 21:18:59

标签: kendo-ui treeview

我有一个kendo Treeview,它显示了父节点,但没有看到子节点。谁能告诉我哪里出错了。我是这个概念的新手。我按照下面的链接,但它没有工作。 http://demos.telerik.com/kendo-ui/treeview/remote-data-binding

struct Foo {
    int x;
    float y;
};

struct Bar {
    Foo const*pFoo;
    bool z;
};

// bear with me while I conjure up a Maybe for C++
class Cached {
public:
    // would have appropriate copy constructor/assignment

    Cached(Cached &&other) {
        m_foo = other.m_foo;
        m_bar = other.m_bar;

        if(m_foo.isJust()) {
            m_bar.pFoo = &m_foo.value();
        } // else already nullptr
    }

    // similar move assignment

private:
    Maybe<Foo> m_foo;
    Bar m_bar;
};

服务:

 function treeView() {
        var treeM = new kendo.data.HierarchicalDataSource({
            schema: {
                data: function (response) {
                    console.log("response" + JSON.stringify(response));
                    var rdata = {};
                    if (response.d) {
                        rdata = JSON.parse(response.d);
                    }
                    else {
                        rdata = response;
                    }
                    return rdata; // ASMX services return JSON in the following format { "d": <result> }.
                },
                model: {
                    hasChildren: true,
                    id: "ID",
                    expanded: true,
                    fields: {
                        ID: { editable: false, nullable: false, type: "string" },
                        LINK: { editable: true, nullable: true, type: "string" },
                                          },
                },
            },
            transport: {
                read: {
                    url: "/getParent",
                    contentType: "application/json; charset=utf-8",
                    type: "POST",
                    datatype: "json"
                },
                parameterMap: function (data, type) {
                    if ((type == "update") || (type == "create") || (type == "destroy")) {
                        console.log('parameterMap:');
                        return JSON.stringify({ "LinksJson": data });
                        console.log(JSON.stringify(data));
                    } else {
                        return data;
                    }
                }
            }
        });

                 $("#treeview1").kendoTreeView({
            dataSource: treeM,
            dataValueField: "ID",
            dataTextField: ["LINK","Name"]
        });

    }

    $("#treeview").on("click", ".k-in", function (e) {
        var tree = $("#treeview").data('kendoTreeView');
        tree.toggle($(e.target).closest(".k-item"));
    });


    $(document).ready(function () {
        treeView();
    });

2 个答案:

答案 0 :(得分:0)

即使您尝试查看子节点,它也会尝试调用getLinks而不是getreports。 从我所看到的,你应该只有一种方法来获得父母和孩子。可以是每个父节点内的数组。 你可以将getlinks中的GetReports方法的数据自己组合起来并给它一个镜头。

答案 1 :(得分:0)

您应该尝试使用硬编码值在此处工作,然后使用服务进行配置。  http://docs.telerik.com/kendo-ui/api/javascript/ui/treeview#configuration-dataSource