jstree:data.rslt未定义

时间:2013-12-02 10:46:55

标签: javascript jquery jstree

我正在使用jstree但是当我尝试获取有关节点的任何信息时,例如文本,位置(例如单击节点或执行拖放),我得到javascript错误data.rslt undefined。

这是我的代码:

<body>
<div id="alog"></div>
<div id="demo">
  <ul>
    <li><a>Team A's Projects</a>
      <ul>
    <li><a>Iteration 1</a>
          <ul>
            <li><a>Story A</a></li>
            <li><a>Story B</a></li>
            <li><a>Story C</a></li>
          </ul>
        </li>
    <li><a>Iteration 2</a>
          <ul>
        <li><a>Story D</a></li>
          </ul>
        </li>
      </ul>
    </li>
  </ul>
</div>

</body>
<script>

$(function () {

    $("#demo").bind("before.jstree", function (e, data) {
        $("#alog").append(data.func + "<br />");
    })

    $("#demo").bind("select_node.jstree", function (e, data) {
        //alert($(data["node"]).find("a:first").text());
    })


    .bind("create.jstree", function (e, data) {
        $.post(
            "/static/v.1.0pre/_demo/server.php", 
            { 
                "operation" : "create_node", 
                "id" : data.rslt.parent.attr("id").replace("node_",""), 
                "position" : data.rslt.position,
                "title" : data.rslt.name,
                "type" : data.rslt.obj.attr("rel")
            }, 
            function (r) {
                if(r.status) {
                    $(data.rslt.obj).attr("id", "node_" + r.id);
                }
                else {
                    $.jstree.rollback(data.rlbk);
                }
            }
        );
    })
    .bind("remove.jstree", function (e, data) {
        data.rslt.obj.each(function () {
            $.ajax({
                async : false,
                type: 'POST',
                url: "/static/v.1.0pre/_demo/server.php",
                data : { 
                    "operation" : "remove_node", 
                    "id" : this.id.replace("node_","")
                }, 
                success : function (r) {
                    if(!r.status) {
                        data.inst.refresh();
                    }
                }
            });
        });
    })
    .bind("rename.jstree", function (e, data) {
        $.post(
            "/static/v.1.0pre/_demo/server.php", 
            { 
                "operation" : "rename_node", 
                "id" : data.rslt.obj.attr("id").replace("node_",""),
                "title" : data.rslt.new_name
            }, 
            function (r) {
                if(!r.status) {
                    $.jstree.rollback(data.rlbk);
                }
            }
        );
    })
    .bind("move_node.jstree", function (e, data) {
        data.rslt.o.each(function (i) {
            $.ajax({
                async : false,
                type: 'POST',
                url: "/static/v.1.0pre/_demo/server.php",
                data : { 
                    "operation" : "move_node", 
                    "id" : $(this).attr("id").replace("node_",""), 
                    "ref" : data.rslt.cr === -1 ? 1 : data.rslt.np.attr("id").replace("node_",""), 
                    "position" : data.rslt.cp + i,
                    "title" : data.rslt.name,
                    "copy" : data.rslt.cy ? 1 : 0
                },
                success : function (r) {
                    if(!r.status) {
                        $.jstree.rollback(data.rlbk);
                    }
                    else {
                        $(data.rslt.oc).attr("id", "node_" + r.id);
                        if(data.rslt.cy && $(data.rslt.oc).children("UL").length) {
                            data.inst.refresh(data.inst._get_parent(data.rslt.oc));
                        }
                    }
                    $("#analyze").click();
                }
            });
        });
    });

});
</script>
</html>

0 个答案:

没有答案