【问题标题】:How does the model structure look like for Kendo TreeView, to bind remote data?Kendo TreeView 的模型结构如何绑定远程数据?
【发布时间】:2016-11-29 05:07:30
【问题描述】:

Kendo TreeView 的模型结构如何,用于绑定远程数据

【问题讨论】:

    标签: model-view-controller kendo-ui treeview


    【解决方案1】:

    我们有一个显示系统位置的树,它具有层次结构。我们使用以下代码: C#代码:

    [HttpPost]
    public async Task<ActionResult> GetChildrenAsync(long? parentId)
        {
            //retrieving location's children by parentId
            //DTO has ChildrenCount field that shows how many children has any particular location
    
            return new JsonResult
            {
                Data = locations.Select(x => new
                {
                    LocationId = x.Id,
                    Name = x.Name,
                    HasChildren = x.ChildrenCount > 0
                }),
                MaxJsonLength = Int32.MaxValue
            };
        }
    

    JS代码:

    var locationDataSource = new kendo.data.HierarchicalDataSource({
            transport: {
                type: "json",
                read: {
                    url: "@Url.Action("GetChildren", "Location")",
                    type: "POST"
                },
                parameterMap: function (data) {
                    return { parentId: data.LocationId };
                }
            },
            schema: {
                model: {
                    id: "LocationId",
                    hasChildren: "HasChildren"
                }
            }
        });
    
        var kendoTree = $("#location-tree").kendoTreeView({
            dataSource: locationDataSource,
            dataTextField: "Name"
        });
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多