【发布时间】:2013-10-23 13:06:27
【问题描述】:
我正在尝试在我的 MVC 4 项目中使用 jstree 插件和 Json 构建树。 但是我做错了,我想不通。
这是我的 Json
[OutputCache(Duration = 0)]
[HttpGet]
public JsonResult GetTree(int idApp)
{
List<TreeNode> list = new List<TreeNode>();
list = ClassData.GetAllClasses(idApp);
var TopHierarchy = list.Where(x => x.ParentId == -1).FirstOrDefault();
SetChildren(TopHierarchy, list);
return Json(TopHierarchy, "application/json", JsonRequestBehavior.AllowGet);
Im my View (Index.cshtml) 我已将 div 放置在要显示树的位置
<div id="treeView"> </div>
我有一个下拉菜单,当我在其中选择一个值时,会触发以下脚本并调用 Json
function ApplicationChange() {
$('#loading').show();
var applicationId = null;
$("#Application option:selected").each(function (i, selected) {
applicationId = $(selected).val();
});
$.ajax({
url: pathTreeView,
type: 'GET',
data: { idApp: applicationId },
success: function (json) {
createJSTrees(json);
},
error: function (xhr, ajaxOptions, thrownError) {
alert(xhr.status);
alert(thrownError);
},
traditional: true
});
}
function createJSTrees(jsonData) {
$("#treeView").jstree({
"json_data": {
"data": jsonData
},
"types": {
"types": {
"default": {
"select_node": function (e) {
this.toggle_node(e);
return false;
}
}
}
},
"plugins": ["themes", "json_data", "types", "ui"]
})
};
当我使用 Firebug 并捕获我的 Json 响应并在 jsfiddle 中使用该字符串时,会生成树并且一切正常。但它不会生成我的应用程序。
有人可以帮我解决这个问题吗?
【问题讨论】:
标签: jquery json asp.net-mvc-4 jstree