I’m trying to load a tree from a JSON string which is being returned from a Java action instead of having it statically inside the HTML.
The original code was like so:
I modified it like so:
The GetTreeData.action returns the following JSON string:
The original code was like so:
<
script
>
$("#treeview-left, #treeview-right").kendoTreeView({
dragAndDrop: true,
dataSource: [
{ text: "Item 1", expanded: true, items: [
{ text: "Item 1.1" },
{ text: "Item 1.2" },
{ text: "Item 1.3" }
] },
{ text: "Item 2", items: [
{ text: "Item 2.1" },
{ text: "Item 2.2" },
{ text: "Item 2.3" }
] },
{ text: "Item 3" }
]
}).data("kendoTreeView");
</
script
>
I modified it like so:
<
script
>
$("#treeview-left, #treeview-right").kendoTreeView({
dragAndDrop: true,
dataSource: {
transport: {
read: {
url: "/site/GetTreeData.action",
dataType: "json"
}
}
}
}).data("kendoTreeView");
</
script
>
The GetTreeData.action returns the following JSON string:
[
{ text: "Item 1", expanded: true, items: [
{ text: "<
a
href
=
'http://localhost:8080/site/GetEmployee.action'
>clear here</
a
>", encoded: false },
{ text: "Item 1.2" },
{ text: "Item 1.3" }
] },
{ text: "Item 2", items: [
{ text: "Item 2.1", items: [
{ text: "Item 2.1.1" },
{ text: "Item 2.1.2" }
] },
{ text: "Item 2.2" },
{ text: "Item 2.3" }
] },
{ text: "Item 3" }
]
If I paste the previous JSON string inside the page and reload it, the tree displays just fine.
So, what am I doing wrong?