@@ -19,7 +19,7 @@ TreeView.propTypes = {
19
19
template : PropTypes . func . isRequired ,
20
20
} ;
21
21
22
- function TreeNodes ( { childrenPath, depth, draggable, nodes, parentNode, template } ) {
22
+ function TreeNodes ( { childrenPath, depth, draggable, nodes, parentNode, template, nodePath } ) {
23
23
return (
24
24
< >
25
25
{ nodes . map ( ( node , index ) => (
@@ -32,28 +32,34 @@ function TreeNodes({ childrenPath, depth, draggable, nodes, parentNode, template
32
32
childrenPath = { childrenPath }
33
33
depth = { depth }
34
34
draggable = { draggable }
35
+ nodePath = { `${ nodePath } [${ index } ]` }
35
36
/>
36
37
) ) }
37
38
</ >
38
39
) ;
39
40
}
40
41
42
+ TreeNodes . defaultProps = {
43
+ nodePath : '' ,
44
+ } ;
45
+
41
46
TreeNodes . propTypes = {
42
47
childrenPath : PropTypes . string ,
43
48
depth : PropTypes . number ,
44
49
draggable : PropTypes . bool ,
45
50
nodes : PropTypes . array ,
46
51
parentNode : PropTypes . object ,
47
52
template : PropTypes . func ,
53
+ nodePath : PropTypes . string ,
48
54
} ;
49
55
50
- function TreeNode ( { node, parentNode, index, template, childrenPath, depth, draggable } ) {
56
+ function TreeNode ( { node, parentNode, index, template, childrenPath, depth, draggable, nodePath } ) {
51
57
const childrenNodes = getValueByPath ( node , childrenPath ) ;
52
58
53
59
return (
54
60
< div draggable = { draggable } >
55
61
< li className = "list-group-item" style = { { marginLeft : `${ depth * 20 } px` , borderTopWidth : '1px' } } >
56
- { template ( node , index , parentNode ) }
62
+ { template ( node , index , parentNode , nodePath ) }
57
63
</ li >
58
64
59
65
{ childrenNodes && (
@@ -63,6 +69,7 @@ function TreeNode({ node, parentNode, index, template, childrenPath, depth, drag
63
69
template = { template }
64
70
childrenPath = { childrenPath }
65
71
depth = { depth + 1 }
72
+ nodePath = { `${ nodePath } .${ childrenPath } ` }
66
73
/>
67
74
) }
68
75
</ div >
@@ -76,4 +83,5 @@ TreeNode.propTypes = {
76
83
childrenPath : PropTypes . string ,
77
84
depth : PropTypes . number ,
78
85
draggable : PropTypes . bool ,
86
+ nodePath : PropTypes . string ,
79
87
} ;
0 commit comments