【问题标题】:JsTree contextmenu callback functions not firingJsTree contextmenu 回调函数未触发
【发布时间】:2012-08-09 19:29:08
【问题描述】:

我正在使用 jstree 库。一个非常好的图书馆,但我遇到了一个问题。上下文菜单的回调不起作用。

我做了一个小的工作示例 - 当您添加/删除/重命名节点时它应该会发出警报,但没有任何反应..

有谁知道为什么不这样做,解决办法是什么?

您可以在线查看工作 - 不工作的示例: http://www.leermetstrips.nl/Content/tree.htm

或者这里:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
    <title>JS tree example</title>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <script src="http://code.jquery.com/jquery-1.8.0.js"></script>      
    <script src="http://cachedcommons.org/cache/jquery-jstree/1.0.0/javascripts/jquery-jstree.js" type="text/javascript"> </script>    
<script type="text/javascript">
$().ready( function() {
    var data = [{"data":"Root node","children":[{"data":"node one","children":[],"metadata":[{"action":"action12"}]}],"metadata":[{"action":"action11"}]}];
    $('#tree').jstree(
        {
            json_data: { data: data },
            plugins: ["themes", "json_data", "ui", "contextmenu", "crrm"],
            // TODO: this does not work, why?
            callback: {
                oncreate: function (NODE, REF_NODE, TYPE, TREE_OBJ, RB) {
                    alert('oncreate');
                },
                onrename: function (NODE, LANG, TREE_OBJ, RB) {
                    alert('onrename');
                },
                ondelete: function (NODE, TREE_OBJ, RB) {
                    alert('ondelete');
                }
            }
        }
        );
});
</script>
</head>
<body>
        <h3>JS tree example</h3>
        <p>When adding, or deleting new nodes, there should be an alert. But there is none. Why?</p>
        <div id="tree" style="border:1px solid;"></div> 
        <p>Click on the tree with your right mouse button to add, rename or delete NEW tree nodes.</p>
</body>
</html>

【问题讨论】:

    标签: jstree


    【解决方案1】:

    jstree 核心功能中没有callback 属性。 所以删除这个:

        callback: {
            oncreate: function (NODE, REF_NODE, TYPE, TREE_OBJ, RB) {
                alert('oncreate');
            },
            onrename: function (NODE, LANG, TREE_OBJ, RB) {
                alert('onrename');
            },
            ondelete: function (NODE, TREE_OBJ, RB) {
                alert('ondelete');
            }
        }
    

    你需要以这种方式在 jstree 对象之外绑定 jstree 事件:

    $('#tree').bind('create.jstree',function (node, ref) {
      alert('oncreate');
    });
    
    $('#tree').bind('rename.jstree',function (node, ref) {
      alert('onrename');
    });
    
    $('#tree').bind('remove.jstree',function (node, ref) {
      alert('ondelete');
    });
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2021-06-22
      • 1970-01-01
      • 2018-03-17
      • 1970-01-01
      • 2015-04-02
      • 2013-10-17
      • 1970-01-01
      相关资源
      最近更新 更多