【发布时间】:2021-07-14 22:44:40
【问题描述】:
大家好,我在使用 ASP.net MVC 的 Kendo UI 时遇到问题,其中混合了用于数据检索的 jQuery。
我当前的 treeview 如下所示:
但是,我希望它看起来更像这样:
我必须使用的 JSON 结构如下所示:
{
"meta": {
"total_results": 193,
"offset": 0,
"total_pages": 1
},
"object_list": [{
"Name": "facebook",
"Description": null,
"Id": "eb8cb0c8c32d1201bff30cf54S4f30889abb23f92b1f7",
"DocumentType": null,
"ProviderId": 2,
"Cat": "Social Networks"
}, {
"Name": "twitter",
"Description": null,
"Id": "732fe66cce4365bc5074384f09b34e787f3f3efe8b55",
"DocumentType": null,
"ProviderId": 2,
"Cat": "Social Networks"
}, {
"Name": "Google",
"Description": null,
"Id": "8b11d6f7b74bf71a7ddbc62dcfead27087e0f3e047e",
"DocumentType": null,
"ProviderId": 2,
"Cat": "Search Engines"
}, {
...ETC...
这看起来需要被格式化为如下所示:
$("#treeview").kendoTreeView({
checkboxes: {
checkChildren: true
},
check: onCheck,
dataSource: [{
id: 1, text: "Categories", expanded: true, spriteCssClass: "rootfolder", items:
[{
id: 2, text: "Social Networks", expanded: true, spriteCssClass: "folder",
items: [
{ id: 3, text: "facebook", spriteCssClass: "html" },
{ id: 4, text: "twitter", spriteCssClass: "html" },
{ id: 5, text: "WhatsApp", spriteCssClass: "image" },
{ id: 6, text: "instagram", spriteCssClass: "image" },
{ id: 7, text: "wechat", spriteCssClass: "image" }
]}, {
id: 8, text: "Search Engines", expanded: true, spriteCssClass: "folder",
items: [
{ id: 9, text: "Google", spriteCssClass: "image" },
{ id: 10, text: "Yahoo!", spriteCssClass: "pdf" }
]}
]
}]
});
所以我的问题 - 由于我无法修改发送给我的 JSON,如何将其转换为正确的 treeview 结构格式?以太解决方案(JQuery 或 ASP.net MVC)就可以了。
任何帮助都会很棒!
更新
【问题讨论】:
标签: javascript jquery asp.net-mvc kendo-ui kendo-treeview