我正在尝试使用 Telerik 的 KendoUI 并从通用处理程序获取树视图以绑定到动态 JSON。
在我的通用处理程序中,我使用 Newtonsoft.Json 将 List 转换为我的 JSON 结果,效果很好,甚至可以与不同的 KendoUI 控件(图表)一起使用。
就构建树视图的 javascript 而言,这是我所拥有的:
var treeSource = new kendo.data.DataSource({
transport: {
read: {
url: "Services/CategoryHandler.ashx",
dataType: "json",
contentType: "application/json; charset=utf-8",
type: "GET"
}
}
});
$("#treeview").kendoTreeView({
dataSource: treeSource
});
以下是返回 JSON 的简短示例:
[
{
"text":"Node 1",
"expanded":true,
"items":null
},
{
"text":"Node 2",
"expanded":true,
"items":null
}
]
“项目”将是树中的子集合。
当我将项目直接添加到数据源时,例如:
var treeview = $("#treeview").kendoTreeView({
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" }
]
})
它工作得很好。当我调用一个写出 JSON 的服务时,它只是不起作用,我的意思是它不起作用,没有数据显示,它是空白的。
关于我可能遗漏的任何想法或关于如何验证我的数据甚至从服务返回甚至正确填充我的数据源的指导?
谢谢