根据提供的代码,使用xm-select版本1.2.4,如果严格遵守父子关系,在点击父节点时会全选所有子节点,再次点击会取消所有选中状态。但是,您可以在子节点全部取消选中的情况下,仍然可以单独选中父节点。

xmSelect.render({
    el: '#tree_one',
    tree: {
        // 是否显示树状结构
        show: true,
        // 是否展示三角图标
        showFolderIcon: true,
        // 是否显示虚线
        showLine: false,
        // 间距
        indent: 10,
        // 默认展开节点的数组, 为 true 时, 展开所有节点
        expandedKeys: false,
        // 是否严格遵守父子模式
        strict: true,
        // 是否开启极简模式
        simple: true,
        // 点击节点是否展开
        clickExpand: true,
        // 点击节点是否选中
        clickCheck: true,
    },
    data: industryList,
    on: function (data) {
        var ids = [];
        var parentIds = [];

        data.arr.forEach(function (item) {
            ids.push(item.value);

            if (item.parent != 0) {
                parentIds.push(item.parent);
            }
        });

        var uniqueIds = Array.from(new Set(ids));
        var uniqueParentIds = Array.from(new Set(parentIds));

        var combinedIds = uniqueIds.concat(uniqueParentIds).join(',');

        $('#industry').val(combinedIds);
    },
});
xm-select 1.2.4 父子节点选中状态控制

原文地址: https://www.cveoy.top/t/topic/qfGP 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录