gpt4 book ai didi

asp.net-mvc - Kendo UI Treeview 绑定(bind)

转载 作者:行者123 更新时间:2023-12-03 22:51:04 25 4
gpt4 key购买 nike

我想做 Kendo TreeView显示第一次加载时的所有节点。我正在使用 Kendo 'Binding to remote data' 示例,但它不能正常工作。它只显示第一级,传递给 Controller ​​操作的 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 };
}

Controller 代码: ( Controller 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);
}

最佳答案

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

return { id : data.Id };

关于asp.net-mvc - Kendo UI Treeview 绑定(bind),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15175927/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com