javascript - jsTree 节点中的 anchor 标记生成错误

标签 javascript jquery html angularjs jstree

我尝试在 li 标签中添加 anchor 标签,但它会产生以下错误,这让我抓狂。我假设这是因为 jsTree 会自动在 li 标签下添加一个 anchor 标签,因此,我将一个 anchor 放在一个 anchor 中。

angular.js:13920TypeError: Cannot read property 'childNodes' of undefined

这是标记:

<div id="jstree_dbs_div">
     <ul>
         {% for type in types %}
             <li data-jstree='{"checkbox_disabled":true}'>
                 {{ type['parent']['text'] }} <span><a href="#">edit</a></span>
             </li>
         {% endfor %}
     </ul>
</div>

如果我删除那个 anchor 标签,它工作正常(即没有错误)。

这是 jsTree 配置:

$jsTree.jstree({
    "core": {
        multiple: false,
    },
    "conditionalselect": function (node, event) {
        return false;
    },
    "plugins" : [ "wholerow", "checkbox", "conditionalselect" ],
    "checkbox": { cascade: "", three_state: false },
}).on("ready.jstree", function() {
    $jsTree.jstree('open_all');
}).on("select_node.jstree", function (e, data) {
    var href = data.node.a_attr.href;
    document.location.href = href;
});

最佳答案

在超时中包装我的 jsTree 配置似乎已经修复了错误。我还添加了一些其他的东西(与原来的问题无关)。

setTimeout(function(){
    $jsTree = $('#jstree_dbs_div');

    $jsTree.jstree({
        "core": {
            multiple: false,
        },
        "conditionalselect": function (node, event) {
            var href = event.target.href;
            document.location.href = href;

            return false;
        },
        "plugins" : [ "wholerow", "checkbox", "conditionalselect" ],
        "checkbox": { cascade: "", three_state: false },
    }).on("ready.jstree", function() {
        $jsTree.jstree('open_all');
    });
}, 0);

关于javascript - jsTree 节点中的 anchor 标记生成错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40134436/

相关文章:

javascript - 获取每个 tr 的 ID 不起作用

javascript - For 循环仅给出计数的最后一个值作为输出

javascript - jQuery API 无法与 JavaScript 一起使用

javascript - 如何将制表符分隔格式的文本文件的内容显示为 html 表格

jquery - Bootstrap 面板折叠创建间隙

C# - 读取 JavaScript 文件并访问变量

javascript - 现代最流行的 ajax 框架是什么?

javascript - 悬停时显示/隐藏 jquery 函数的平滑过渡?

javascript - 希望在 Bootstrap 中为列设置相同的高度 - 没有表格

php - 在 html 中显示下拉列表中的值数据