填充KendoUi树视图与RavenDB文件

编程入门 行业动态 更新时间:2024-10-24 06:36:10
本文介绍了填充KendoUi树视图与RavenDB文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我使用MVC4和C#。我有一个KendoUI树形,我想从RavenDB数据来填充它。

I am using MVC4 and C#. I have a KendoUI Treeview and I'd like to populate it with data from RavenDB.

在演示他们使用这样的:

In the demo they use this:

public JsonResult Employees(int? id) { var dataContext = new NorthwindDataContext(); var employees = from e in dataContext.Employees where (id.HasValue ? e.ReportsTo == id : e.ReportsTo == null) select new { id = e.EmployeeID, Name = e.FirstName + " " + e.LastName, hasChildren = e.Employees.Any() }; return Json(employees, JsonRequestBehavior.AllowGet); }

注意参数ID - 这是一个int。在RavenDb文件的ID都是字符串如。 myDco / 231 ...

Notice the argument "id" - it's an int. In RavenDb document ID's are strings eg. myDco/231...

想象一下,这是一个标准的文件:

Imagine this is a standard document:

{ "CreationDate": "12/12/2012 8:07:59 PM", "Name": "jkljklk", "Type": "kljkljkljkljkl", "Description": "ljkljklj", "CreatedByUser": "ljklklkljklj", "Deleted": false, "Status": "NEW", "Parent": "product/546" }

我将如何填充树视图?

How would I populate the treeview?

推荐答案

我想通了这一点。

我改变了我的RavenDB文件包含所有的儿童名单:

I changed my RavenDB Document to include a list of all its children:

{ "CreationDate": "12/12/2012 9:33:34 PM", "Name": "hohoho", "Type": "hohohoh", "Description": "hohohoh", "CreatedByUser": "hohohoh", "Deleted": false, "Status": "NEW", "Parent": "ohohohoh", "Children": [ "item/1", "item/2", "item/3" ] }

我再回到我的项目清单通过控制器的视图,然后通过他们迭代,所有的孩子追加到他们的正确的父节点:

I then returned a list of my items to the View via the controller and then iterated through them, appending all the children to their correct parent nodes:

@(Html.Kendo().TreeView().Name("TreeView").DragAndDrop(true) .Items(treeview => { foreach (var myItem in Model) { var myItemName = myItem.Name; var children = myItem.Children; treeview.Add().Text(myItemName ).Expanded(false).Items(branch => { if (children != null) { foreach (var child in children) { branch.Add().Text(child); } } }); } } ))

无论如何,感谢您的答复:)

Anyway, thanks for the responses :)

希望这有助于别人一天。

Hope this helps someone else one day.

更多推荐

填充KendoUi树视图与RavenDB文件

本文发布于:2023-05-28 06:53:34,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/315078.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:视图   文件   KendoUi   RavenDB

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!