0

私は KendoUI treeview Binding to remote data を使用しています。以下は私のコードです:

            <script>
            var serviceRoot = "/kendoui";

            var Taxonomys = {
                schema: {
                    model: {
                        id: "Name",
                        hasChildren: function () {
                            return false;
                        }
                    }
                },
                transport: {
                    read: {
                        url: function (options) {
                            return kendo.format("http://localhost/MySite/MySiteService.svc/Organization/{1}/Project/{0}/Taxonomy?includeSchema=0", options.Name);
                        }
                    }
                }
            };

            var Projects = {
                schema: {
                    model: {
                        id: "Name",
                        hasChildren: function () {
                            return true;
                        },
                        children: Taxonomys
                    }
                },
                transport: {
                    read: {
                        url: function (options) {
                            return kendo.format("http://localhost/MySite/MySiteService.svc/Organization/{0}/Project", options.Name);
                        }
                    }
                }
            };

            homogeneous = new kendo.data.HierarchicalDataSource({
                transport: {
                    read: {
                        url: "http://localhost/MySite/MySiteService.svc/Organization ",
                        dataType: "jsonp"
                    }
                },
                schema: {
                    model: {
                        id: "Name",
                        hasChildren: function () {
                            return true;
                        },
                        children: Projects
                    }
                }
            });

            $("#treeview").kendoTreeView({
                dataSource: homogeneous,
                dataTextField: ["Name", "Name", "Name"]
            });
        </script>

Taxonomys では、 Organization name が必要です。

http://localhost/MySite/MySiteService.svc/Organization/{1}/Project/{0}/Taxonomy?includeSchema=0

ただし、「url: function (options) {}」のオプションにはプロジェクトの名前しかありません。プロジェクトの親の名前を取得するにはどうすればよいですか?

4

1 に答える 1

0

ツリー内のノードを指定すると、ツリー内parentを移動するためにメソッドを使用する必要があります。

例。選択したノードの祖父母を取得したい場合は、次を使用する必要があります。

var select = treeview.select();
console.log("select", select);
if (select.length) {
    var parent = treeview.parent(select);
    if (parent.length) {
        console.log("parent", treeview.dataItem(parent));
        var grandparent = treeview.parent(parent);
        if (grandparent.length) {
            console.log("grandparent", treeview.dataItem(grandparent));
        } else {
            console.log("has no grandfather")
        }
    } else {
        console.log("has no father")
    }
} else {
    console.log("select a node");
}

ご覧のとおり、ノードが選択されていること、そのノードに父と祖父があることを確認するための検証を行っています。

そのアイテムのデータも表示しています。これにより、モデルの一部である限り、組織とプロジェクトを取得できるはずです。

于 2013-06-05T13:16:59.473 に答える