如何使用MVC创建HierarchialDataSource并将其用作DataSource的TreeView?
我已经创建了一个分层结构,它作为Json从控制器返回,但是TreeView只显示顶级节点。是否需要在TreeView上设置一个属性来指示DataSource是层级的?
我看到了几个使用JS和kendo.data库的客户端示例,但我找不到服务器端的等效程序集。
谢谢你的帮助。
发布于 2013-08-16 20:50:31
据我所知,要绑定的模型的属性必须与HierarchicalDataSource:http://docs.kendoui.com/api/framework/hierarchicaldatasource匹配
我使用树视图来显示菜单结构,所以这是我的模型:
public class Menu
{
public int Id { get; set; }
public int? ParentId { get; set; }
public string Description { get; set; }
public int id
{
get { return this.Id; }
}
public bool hasChildren { get; set; }
}我必须显式地使用这种大小写实现id和hasChildren属性(在将模型推送到视图之前,我将根据查询填充hasCHildren属性)。
我不确定这是否是正确的方法(仍然在努力寻找官方信息),但至少它是有效的。
发布于 2016-12-12 20:47:24
在您的cshtml文件中使用此命令:
@(Html.Kendo().TreeView()
.Name("trvReport")
.DataTextField("Name")
.DataSource(dataSource => dataSource
.Read(read => read.Action("ReportType", "Read"))
.Model(model =>
{
model.Id("Id");
model.Field("Name", typeof(string));
model.Children("Reports");
model.HasChildren("HasReports");
})
)
)在模型中实现HasChildren,如下所示:
public class ReportType
{
public int Id { get; set; }
public string Name { get; set; }
public ICollection<Report> Reports { get; set; }
[NotMapped]
public bool HasReports { get { return Reports.Count() > 0; } }
}https://stackoverflow.com/questions/16238654
复制相似问题