3

Here is my tree view of KendoUI:

<script src="~/scripts/kendo.all.min.js"></script>
            <script type="text/javascript">

            $(document).ready(function () {


                var regions = {
                    type: "odata",
                    transport: {
                        read: function (options) {
                            $.ajax(
                            {
                                type: "POST",
                                url: "Territory/AllRegions?countryID=?" + options.ID,
                                contentType: "application/json; charset=utf-8",
                                dataType: 'json',
                                success: function (data) {
                                    $("#treeview").data("kendoTreeView").dataSource.data(data);
                                }
                            });
                        },

                    },
                    schema: {
                        model: {
                            hasChildren: function () {
                                return false;
                            }
                        }
                    }
                };

                var countries = {
                    type: "odata",
                    schema: {
                        model: {
                            id: "Id",
                            hasChildren: "HasChildren",
                            children: regions
                        }
                    },
                    transport: {
                        read: function (options) {
                            $.ajax(
                            {
                                type: "POST",
                                url: "Territory/AllCountries?territoryID=?" + options.ID,
                                contentType: "application/json; charset=utf-8",
                                dataType: 'json',
                                success: function (data) {
                                    $("#treeview").data("kendoTreeView").dataSource.data(data);
                                }
                            });
                        }
                    }
                };

                var Territories = new kendo.data.HierarchicalDataSource({
                    type: "odata",
                    transport: {
                        read:  function (options) {
                            $.ajax(
                            {
                                type: "POST",
                                url: "Territory/AllTerritories",
                                contentType: "application/json; charset=utf-8",
                                dataType: 'json',
                                success: function (data) {
                                    $("#treeview").data("kendoTreeView").dataSource.data(data);
                                }
                            });
                        }
                    },
                    schema: {
                        model: {
                            hasChildren: "HasChildren",
                            Id: "ID",
                            children: countries
                        }
                    }
                });

                $("#treeview").kendoTreeView({
                    dataSource: Territories,
                    dataTextField: ["Name", "Name", "Name"],
                    dataValueField:"ID"
                });
            });

        </script>

The hierarchy is Territories->countries->regions I can see the territories populating, but I am unable to fetch the ID property of selected Territory so that countries can be populated, that is in ajax call, options.ID is undefined there.

Teo
  • 125
  • 1
  • 11
user3014311
  • 438
  • 8
  • 27
  • [link](http://demos.telerik.com/kendo-ui/treeview/odata-binding).. You can refer this site. – Aarthi Chandrasekaran Jul 04 '14 at 11:24
  • Any luck on this? Running in to basically the same thing. – DennisWelu Sep 17 '14 at 16:42
  • 1
    Not sure if it will fix your problem, but within the `success` function of your ajax calls, you should be calling `options.success(data);` rather than using that unnecessary jQuery statement to do it. Using `options.success(data);` will load the DataSource and then by association the widget its bound to. – Brett Dec 18 '14 at 21:46
  • there is problem in hasChildren: "HasChildren"... – Parthiv Pandya Mar 04 '15 at 10:41

0 Answers0