我做了一个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>并没有返回树的列表。
想问下,List<>返回怎么处理显示结构啊?
我用JsTree试过List<>返回,
在 success: function (data) {
return data.List
}
就可以了,但dynaTree不知道怎么做。

解决方案 »

  1.   


    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; }
        }定义treenodes节点
    递归数据填充treenodes
    返回数据:context.Response.Write(JavaScriptHelper.JsonSerializer.Serialize(nodes));
      

  2.   

    dyTree 是需要一些固定的属性名称的,不是你从数据库查的什么列名就往里面填充什么,它识别不了
      

  3.   

    前端:
    function GetDynaTreeSource() {
        $.ajax({
            url: /Photo/Photo.ashx?type=getdynatreesource&t=" + (new Date()).valueOf(),
            dataType: "json",
            type: "post",
            timeour: 6000,
            success: function(data) {
                if (data) {
                    InitDynaTree(data);
                                }
            },
            error: function (e, x) {
                            
            }
        });
    }
    function InitDynaTree(data) {
        $("#myTree").dynatree({
            persist: true,
            checkbox: false,
            selectMode: 3,
            children: data,
            onActivate: function(node) {
                
            },
        });}