首页 新闻 会员 周边 捐助

ztree 中0a138f - JavaScript 运行时错误: 无法获取未定义或 null 引用的属性“init”

0
悬赏园豆:50 [待解决问题]
 
<link href="~/ZTree/css/zTreeStyle/zTreeStyle.css" rel="stylesheet" />
<script src="~/ZTree/js/jquery-1.4.4.min.js"></script>
<script src="~/ZTree/js/jquery.ztree.all-3.5.min.js"></script>
 
<script type="text/javascript">
    //异步加载节点
    var setting4 =
        {
            data:
                {
                    simpleData:
                        {
                            enable: true,
                            idKey: "id",
                            pIdKey: "pId",
                            rootPId: 0
                        },
                    async:
                        {
                            //异步加载
                            enable: true,
                            url: "/api/values/",
                            autoParam: ["id""name""pId"]
                        },
                    callback:
                        {
                            beforeExpand: beforeExpand,
                            onAsyncSuccess: onAsyncSuccess,
                            onAsyncError: onAsyncError
                        }
                }
 
        }
    function createTree() {
        alert("进来");
        $.ajax({
            url: '/api/values/'//url  action是方法的名称
            data: { id: 0 },
            type: 'Get',
            dataType: "json"//可以是text,如果用text,返回的结果为字符串;如果需要json格式的,可是设置为json
            success: function (data) {
                $(data).each(function (index, obj) {
 
                    $.fn.zTree.init($("#treeDemo4"), setting4, eval('(' + obj.name + ')'));
                })
 
 
            },
            error: function (msg) {
                alert(" 数据加载失败!" + msg);
            }
 
        });
 
    }
    function beforeExpand(treeId, treeNode) {
        if (!treeNode.isAjaxing) {
            return true;
        } else {
            alert("zTree 正在下载数据中,请稍后展开节点。。。");
            return false;
        }
    }
 
    function onAsyncSuccess(event, treeId, treeNode, msg) {
 
    }
    function onAsyncError() {
        alert(" 数据加载失败");
    }
 
    $(document).ready(function () {
        createTree();
    });
</script>
 
<div>
    <ul id="treeDemo4" class="ztree"></ul>
</div>
leoyi的主页 leoyi | 初学一级 | 园豆:152
提问于:2016-05-17 15:04
< >
分享
所有回答(1)
0

查查网络请求,看是不是ztree js文件没有请求到

life++ | 园豆:312 (菜鸟二级) | 2016-05-17 16:29

谢谢,能告诉我如何对父节点添加子节点吗

支持(0) 反对(0) leoyi | 园豆:152 (初学一级) | 2016-05-17 16:38
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册