DynaTree返回List的问题
我做了一个List<>的Tree结构,返回是这样的:
List<myTreeNode> dyTree = Tdata.GetDyTreeMList();
object obj = new { Success = true, Message = "OK", List = dyTree };
return Json(obj, JsonRequestBehavior.AllowGet);
页面上:
<script type="text/javascript">
alert("QQ");
$(document).ready(function () {
// Attach the dynatree widget to an existing <div id="tree"> element
// and pass the tree options as an argument to the dynatree() function:
$("#tree").dynatree({
initAjax: {
type: "POST",
dataType: "json",
url: "/myTs/GetJsTreeList",
data: { id: 10 },
error: function (exp) {
alert('Error : ' + exp.responseText);
}
},
onActivate: function (node) {
alert("You activated " + node.data.icon);
}
});
});
</script>
public class TreeNodes
{
/// <summary>
/// 构造函数
/// </summary>
/// <param name="t">title:节点显示的名称</param>
/// <param name="k">key:节点的值</param>
/// <param name="cb">是否显示checkbox</param>
/// <param name="isDel">是否允许删除</param>
public TreeNodes(string t, string k, bool cb, bool isDel)
{
children = new List<TreeNodes>();
expand = true;
isFolder = true;
title = t;
key = k;
hideCheckbox = cb;
isCanBeDel = isDel;
keyboard = true;
focus = false;
}
public string title { get; set; }
public string key { get; set; }
public bool expand { get; set; }
public bool isFolder { get; set; }
public bool hideCheckbox { get; set; }
public bool isCanBeDel { get; set; }
public List<TreeNodes> children { get; set; }
public bool keyboard { get; set; }
public bool focus { get; set; }
}
context.Response.Write(JavaScriptHelper.JsonSerializer.Serialize(nodes));