2016-11-29 4 views

答えて

0

階層構造を持つシステムの場所を表示するツリーがあります。 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" 
    }); 
私たちは、次のコードを使用します
関連する問題