问题:
使用 HierarchicalDataSource 将 Kendo Treeview 绑定(bind)到远程数据源时遇到问题
Object Doesn't support property or method 'level'
我认为问题与我的 json 响应有关,因为它是用一大堆转义字符编码的;我不知道如何强制 Transport.Read.Url 使用 $.parseJson(data)。我所能做的就是将 url 提供给我在 Controller 中的操作;但我的 Controller 的结果是纯 json,有很多转义字符......请帮忙
Controller :
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using Newtonsoft.Json;
[HttpPost]
public JsonResult TreeItems(int? jobId, int? parentJobId)
{
var data = new List<object>()
{
new
{
NodeId = 1,
caption = "test1",
hasChildren = true,
items = new List<object>()
{
new
{
NodeId = 2,
caption = "test2",
hasChildren = false,
parentId = "1"
},
new
{
NodeId = 3,
caption = "test3",
hasChildren = false,
parentId = "1"
},
}
}
};
return Json(JsonConvert.SerializeObject(data), JsonRequestBehavior.AllowGet);
}
JavaScript:
var ds1 = new kendo.data.HierarchicalDataSource(
{
transport:
{
read:
{
url: urlToTreeItems
, dataType: "json"
, type: "POST"
},
schema:
{
model:
{
id: "id",
text: "caption",
hasChildren: "hasChildren"
}
},
}
});
var tv = $("#test").kendoTreeView(
{
dataSource: ds1
}).data("kendoTreeView");
回复:
"[{\"NodeId\":1,\"caption\":\"test1\",\"hasChildren\":true,\"items\":[{\"NodeId\":2,\"caption\":\"test2\",\"hasChildren\":false,\"parentId\":\"1\"},{\"NodeId\":3,\"caption\":\"test3\",\"hasChildren\":false,\"parentId\":\"1\"}]}]"
//EDITED:还想提一下我尝试了以下方法;它只是为节点文本显示“未定义”,并且树节点不展开
var ds2 = new kendo.data.HierarchicalDataSource(
{
transport:
{
read: function (options)
{
Ajax(urlToTreeItems, false, null, "POST", null, "application/json; charset=utf-8", "json",
function (result)
{
var jResult = $.parseJSON(result);
options.success(jResult);
});
},
schema:
{
model:
{
id: "NodeId",
text: "caption",
hasChildren: "hasChildren"
}
},
}
});
var tv = $("#test").kendoTreeView(
{
dataSource: ds2
}).data("kendoTreeView");
最佳答案
尝试 :
schema:
{
model:
{
id: "NodeId",
children: "items"
hasChildren: "hasChildren"
}
}
关于c# - Kendo Treeview 和阅读网址,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26557746/