Kendo ui 如何在KendoUI TreeView中获取ID属性

Kendo ui 如何在KendoUI TreeView中获取ID属性,kendo-ui,kendo-treeview,Kendo Ui,Kendo Treeview,这是我的KendoUI树视图: <script src="~/scripts/kendo.all.min.js"></script> <script type="text/javascript"> $(document).ready(function () { var regions = { type: "odata",

这是我的
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>

$(文档).ready(函数(){
变量区域={
类型:“odata”,
运输:{
阅读:功能(选项){
$.ajax(
{
类型:“POST”,
url:“Territory/AllRegions?countryID=?”+options.ID,
contentType:“应用程序/json;字符集=utf-8”,
数据类型:“json”,
成功:功能(数据){
$(“#treeview”).data(“kendoTreeView”).dataSource.data(数据);
}
});
},
},
模式:{
型号:{
hasChildren:函数(){
返回false;
}
}
}
};
var国家={
类型:“odata”,
模式:{
型号:{
id:“id”,
hasChildren:“hasChildren”,
儿童:区域
}
},
运输:{
阅读:功能(选项){
$.ajax(
{
类型:“POST”,
url:“Territory/AllCountries?territoryID=?”+options.ID,
contentType:“应用程序/json;字符集=utf-8”,
数据类型:“json”,
成功:功能(数据){
$(“#treeview”).data(“kendoTreeView”).dataSource.data(数据);
}
});
}
}
};
var territions=new kendo.data.hierarchycalDataSource({
类型:“odata”,
运输:{
阅读:功能(选项){
$.ajax(
{
类型:“POST”,
url:“地区/所有地区”,
contentType:“应用程序/json;字符集=utf-8”,
数据类型:“json”,
成功:功能(数据){
$(“#treeview”).data(“kendoTreeView”).dataSource.data(数据);
}
});
}
},
模式:{
型号:{
hasChildren:“hasChildren”,
Id:“Id”,
儿童:国家
}
}
});
$(“#treeview”).kendoTreeView({
数据来源:领土,
dataTextField:[“名称”、“名称”、“名称”],
dataValueField:“ID”
});
});
层次结构是Territions->countries->regions 我可以看到领土正在填充,但我无法获取所选领土的
ID
属性,以便可以填充国家,即在ajax调用中,
options.ID在那里未定义。

。。你可以参考这个网站。运气好吗?运行到基本相同的事情。不确定它是否会解决您的问题,但是在ajax调用的
success
函数中,您应该调用
options.success(data)而不是使用不必要的jQuery语句。使用
options.success(数据)
将加载数据源,然后通过关联加载绑定到的小部件。hasChildren中存在问题:“hasChildren”。。。