2013-03-02 201 views
2

我想製作Kendo TreeView,它顯示第一次加載時的所有節點。我正在使用Kendo'綁定到遠程數據'示例,但它無法正常工作。它僅顯示第一級,傳遞給控制器​​操作的ID始終爲空。 請幫幫我。Kendo UI樹視圖綁定

查看代碼:

@(Html.Kendo().TreeView() 
    .Name("treeview") 
    .DataTextField("Title") 
    .ExpandAll(true) 
    .LoadOnDemand(false) 
    .DataSource(dataSource => dataSource 
    .Read(read => read.Action("Employees", "Follow").Data("addData")))) 

function addData(data) { 
    return { id: data.id }; 
} 

控制器代碼:(控制器Follow

public System.Web.Mvc.JsonResult Employees(int? id) 
{ 
    System.Collections.Generic.List<FollowType> List = 
     new System.Collections.Generic.List<FollowType>(); 

    if (id.HasValue == true) { 
     List = FollowTypeList.FindAll(current => current.ParentId == id); 
    } else { 
     List = FollowTypeList.FindAll(current => current.ParentId == null); 
    } 

    System.Collections.Generic.List<Kendo.Mvc.UI.TreeViewItemModel> NodeList = 
     new System.Collections.Generic.List<Kendo.Mvc.UI.TreeViewItemModel>(); 

    foreach (CommonData.Domain.FollowType item in List) 
    { 
     NodeList.Add(new Kendo.Mvc.UI.TreeViewItemModel() { 
      Id = item.Id.ToString(), 
      Text = item.Title, 
      HasChildren = FollowTypeList.Exists(c => c.Id == item.ParentId) 
     }); 
    } 

    return Json(NodeList, System.Web.Mvc.JsonRequestBehavior.AllowGet); 
} 

回答

0

我想,在你的JavaScript代碼,數據的id領域應該是Id(是注意大小寫):

return { id : data.Id };