jquery - jsTree不创建特定类型的节点

标签 jquery jstree

我遵循了 http://www.jstree.com/demo/types 的最后一个示例中的代码片段创建给定类型的节点,但我不知道为什么它不起作用。

HTML 片段:

    <form>
        <button id="buttonAddMenu" type="button">Créer Menu</button>
        <button id="buttonAddParameter" type="button">Créer Paramètre</button>
        <button id="buttonRename" type="button">Renomer</button>
        <button id="buttonRemove" type="button">Supprimer</button>
        <button id="buttonShowData" type="button">Show Data</button>
    </form>
    <div id="checkListParams">
    <ul>
        <li id="new001"><a href="#">Root menu 1</a></li>
        <li id="new002"><a href="#">Root menu 2</a>
            <ul>
                <li><a href="#">Menu 2.1</a></li>
                <li><a href="#">Menu 2.2</a>
                    <ul>
                        <li rel="parameter"><a href="#">Parameter A</a></li>
                    </ul>
                </li>
            </ul>
        </li>
    </ul>
    </div>

Javascript:

$(document).ready(function() {
//================
//Configuring tree
//================
$("#checkListParams").jstree({ 
    "ui" : {
        "select_limit": 1
    },
    "contextmenu" : {
        "select_node": true
    },
    "hotkeys" : {
        "del": false //disable deleting nodes only via DEL key
    },
    "types" : {
        "valid_children" : [ "default" ],
        "use_data" : true,
        "types" : {
            "default" : {
                "valid_children" : [ "all" ]
            },
            "parameter" : {
                "icon" : { 
                    "image" : "site/media/img/icons/checklist_parameter.png" 
                },
                "valid_children" : [ "none" ],
                "create_node": false
            }
        }
    },
    "core" : { "initially_open" : [ "all" ] },
    "plugins" : [ 
    "themes", "html_data", "xml_data", "ui", "crrm", "dnd", 
    "contextmenu", "hotkeys", "types"
    ]
});

//==========================
//Configuring button actions
//==========================
$("#buttonAddMenu").click(function() {
    $("#checkListParams").jstree("create");
});

$("#buttonAddParameter").click(function() {
    //$("#checkListParams").jstree("create", null, "inside"); //works!
    $("#checkListParams").jstree("create", null, "inside", { "attr" : { "rel" : "parameter" } });
});

$("#buttonRemove").click(function() {
    $("#checkListParams").jstree("remove");
})

$("#buttonRename").click(function() {
    $("#checkListParams").jstree("rename");
})

$("#buttonShowData").click(function() {
    var nodes = $("#checkListParams").jstree("get_xml", {
        "li_attr" : [ "id" , "class", "rel" ]
    });
    alert(nodes);
})

});

线路

$("#checkListParams").jstree("create", null, "inside", { "attr": { "rel": "parameter"} });

不工作。我尝试将类型更改为“默认”,但没有成功...此外,我没有收到错误消息(我不喜欢在事情不运行时没有收到错误消息)。

提前谢谢您。

更新

使用http://osdir.com/ml/jstree/2011-04/msg00126.html中的说明解决了。 明确列出所有有效的子项(而不是使用“全部”)解决了问题。

明天我会检查 jsTree 问题页面中是否有类似的 bug,也许会添加一个新的 bug。

无论如何,谢谢。

最佳答案

只是按照一些人的要求重复上述更新:

使用http://osdir.com/ml/jstree/2011-04/msg00126.html中的说明解决了。显式列出所有有效的子项(而不是使用“全部”)解决了问题。

明天我会检查 jsTree 问题页面中是否有类似的 bug,也许会添加一个新的 bug。

无论如何,谢谢。

关于jquery - jsTree不创建特定类型的节点,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6341279/

相关文章:

javascript - 在 JsTree 中排序时拖放不起作用

jstree - 如何在不重新加载的情况下更新jstree节点值

javascript - JsTree、JsTreeGrid - 制作网格时获取父节点

jquery - 无法点击用jquery创建的表

jquery - JSON 控制台显示对象,但在使用 Vue.js 后给出未定义的属性错误

javascript - jQuery 阶梯滑出列表效果

javascript - 检测隐藏选择元素上的更改事件

javascript - 自定义js树上的图标

php - Ajax 文件浏览器;有哪些好的做法

c# - mvc 4 底部的脚本 - 不在 View 页面中执行 &lt;scripts>