如何在KendoUI TreeView中获取ID属性

时间:2014-06-21 12:48:10

标签: kendo-ui kendo-treeview

以下是我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>

层次结构是 Territories-&gt; countries-&gt; regions  我可以看到填充的区域,但是我无法获取所选 Territory ID属性,以便可以填充 countries ,即在ajax调用中, 那里options.ID未定义。

0 个答案:

没有答案