首页 > 解决方案 > 是否可以在jstree中为父级设置单选按钮和为子级设置复选框按钮?

问题描述

我希望父节点像单选按钮一样,但它的所有子节点都是复选框按钮,单独使用“multiple:true”是不够的,我想要的是通过单击/检查一个父节点,所有其他父节点应该是未选中,请参见以下代码,希望有人能帮助我找出解决方案,谢谢。

.on('changed.jstree', async (e, data) => {
const node = data.instance.get_node(data.node, true); // current clicked and checked parent checkbox
let siblings = node.siblings('li[aria-level="1"]'); // all other parent checkboxs
for (let i = 0; i < siblings.length; i++) {
    let sibling = siblings[i];
    sibling.ariaSelected = false; // all other parent checkboxs should be unchecked, that's my objective!
    $.jstree.reference('#').refresh(sibling); // try to reflect change in UI but not working
}
$.jstree.reference('#').redraw(true); // try to reflect changes in UI but not working
});

标签: javascriptjstree

解决方案


推荐阅读