我尝试在 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/