Skip to content

Commit fae2b46

Browse files
author
Moaead Yahya
committed
2.0.4 fix duplicate key
1 parent e136372 commit fae2b46

File tree

2 files changed

+17
-13
lines changed

2 files changed

+17
-13
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@r365/react-checkbox-tree",
3-
"version": "2.0.3",
3+
"version": "2.0.4",
44
"description": "A simple and elegant checkbox tree for React.",
55
"author": "Jake Zatecky",
66
"license": "MIT",

src/js/NodeModel.js

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -35,18 +35,22 @@ class NodeModel {
3535
nodes.forEach((node, index) => {
3636
const isParent = this.nodeHasChildren(node);
3737

38-
this.flatNodes[node.value] = {
39-
label: node.label,
40-
value: node.value,
41-
children: node.children,
42-
parent,
43-
isParent,
44-
isLeaf: !isParent,
45-
showCheckbox: node.showCheckbox !== undefined ? node.showCheckbox : true,
46-
disabled: this.getDisabledState(node, parent, disabled, noCascade),
47-
treeDepth: depth,
48-
index,
49-
};
38+
if (!this.flatNodes[node.value]) {
39+
this.flatNodes[node.value] = {
40+
label: node.label,
41+
value: node.value,
42+
children: node.children,
43+
parent,
44+
isParent,
45+
isLeaf: !isParent,
46+
showCheckbox: node.showCheckbox !== undefined ? node.showCheckbox : true,
47+
disabled: this.getDisabledState(node, parent, disabled, noCascade),
48+
treeDepth: depth,
49+
index,
50+
};
51+
} else {
52+
this.flatNodes[node.value].children = [...this.flatNodes[node.value].children, ...node.children]
53+
}
5054
this.flattenNodes(node.children, node, depth + 1);
5155
});
5256
}

0 commit comments

Comments
 (0)