0

I use KendoUI treeview Binding to remote data , below is my code:

            <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>

in the Taxonomys , I need Organization name .

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

but options in "url: function (options) {}" only has Projects's Name. How can I get Projects's Parent's Name?

user2454489
  • 43
  • 1
  • 6

1 Answers1

0

Given a node in the tree you should use parent method for navigating through the tree.

Example. If we want to get the grandparent of the selected node we should use:

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");
}

As you can see I'm doing validation to check that there is a node selected, that it has a father and it has grandfather.

I'm also showing the data of that item. With this you should be able of getting the Organization and the the Project as far as they are part of the model.

OnaBai
  • 40,767
  • 6
  • 96
  • 125
  • How can I do it in transport: { read: { url: function (options) { return kendo.format("http://localhost/MySite/MySiteService.svc/Organization/{1}/Project/{0}/Taxonomy?includeSchema=0", options.Name); } } } – user2454489 Jun 06 '13 at 10:00
  • Is the question how to get information from the node being expanded? – OnaBai Jun 06 '13 at 10:06