[英]How do I load the following HTTP response in a Kendo UI treeview?
<ArrayOfNode xmlns:i="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://....Controllers">
<Node>
<notificationType>Test1 (20)</notificationType>
<notifications xmlns:d3p1="http://...Serialization/Arrays">
<d3p1:string>3298</d3p1:string>
<d3p1:string>983932</d3p1:string>
... (20 items here)
</Node>
<Node>
<notificationType>Test2 (40)</notificationType>
<notifications xmlns:d3p1="http://...Serialization/Arrays">
<d3p1:string>ABCD</d3p1:string>
<d3p1:string>AZYX</d3p1:string>
...(40 items here)
</Node>
</ArrayOfNode>
This is not working: 这不起作用:
var notificationTypes = new kendo.data.HierarchicalDataSource({
transport: {
read: {
url: "http://..."
}
},
schema: {
model: {
notificationType: "notificationType",
notifications: "notifications",
children: "notifications",
string: "string",
hasChildren: true
}
}
});
$("#treeview").kendoTreeView({
dataSource: notificationTypes,
checkboxes: {
checkChildren: true
},
dataTextField: ["notificationType", "notifications"]
});
It only loads the parent node but I want to make the "notifications" of each node the children items for the tree. 它仅加载父节点,但我想使每个节点的“通知”成为树的子项。
It should look like this: 它看起来应该像这样:
-- 3298 -3298
-- 983932 -983932
-- ABCD - A B C D
-- 983932 -983932
I have fixed the problem. 我已经解决了这个问题。
Here's the script code: 这是脚本代码:
<script language="javascript" type="text/javascript">
$(function()
{
var data = new kendo.data.HierarchicalDataSource({
transport: {
read: {
url: "../api/notifications/byuserid/10078261",
contentType: "application/json"
}
},
schema: {
model: {
children: "notifications"
}
}
});
$("#treeview").kendoTreeView({
dataSource: data,
checkboxes: {
checkChildren: true
},
dataTextField: ["notificationType", "NotificationDesc"]
});
});
</script>
And here's the API: 这是API:
namespace X.Controllers
{
public class NotificationsController : ApiController
{
public List<Node> getNotifications(int id)
{
var bo = new HomeBO();
var list = bo.GetNotificationsForUser(id);
var notificationTreeNodes = (from GBLNotifications n in list
where n.NotificationCount != 0
select new NotificationTreeNode(n)).ToList();
var li = notificationTreeNodes.Select(no => new Node
{
notificationType = no.NotificationNode.NotificationType + " " + "(" + no.NotificationNode.NotificationCount + ")", notifications = bo.GetNotificationsForUser(id, no.NotificationNode.NotificationTypeId).Cast<GBLNotifications>().Select(item => new Notification
{
ID = item.NotificationId, NotificationDesc = item.NotificationDescription
}).ToList()
}).ToList();
return li;
}
}
public class Node
{
public List<Notification> notifications;
public string notificationType
{
get;
set;
}
}
public class Notification
{
public int ID
{
get;
set;
}
public string NotificationDesc
{
get;
set;
}
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.