【问题标题】:Kendo UI treeview bindingKendo UI 树视图绑定
【发布时间】:2013-02-17 00:40:36
【问题描述】:

我想制作一个剑道TreeView,它会在第一次加载时显示所有节点。我正在使用 Kendo 'Binding to remote data' 示例,但它不能正常工作。它只显示第一级,传递给控制器​​操作的 id 始终为空。 请帮帮我。

查看代码:

@(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);
}

【问题讨论】:

    标签: asp.net-mvc data-binding binding kendo-ui kendo-treeview


    【解决方案1】:

    我猜在您的 javascript 代码中,id 数据字段应该是 Id(注意大小写):

    return { id : data.Id };
    

    【讨论】: