File tree Expand file tree Collapse file tree 4 files changed +111
-8
lines changed Expand file tree Collapse file tree 4 files changed +111
-8
lines changed Original file line number Diff line number Diff line change @@ -68,3 +68,8 @@ export default function App() {
68
68
69
69
<<< @/../src/pages/base_flat_data.tsx
70
70
<DemoIframe url =" /base_flat_data " />
71
+
72
+ ## 基础使用-树形数据
73
+
74
+ <<< @/../src/pages/base_tree_data.tsx
75
+ <DemoIframe url =" /base_tree_data " />
Original file line number Diff line number Diff line change @@ -59,6 +59,9 @@ export default function PageLayout(props: {}) {
59
59
.main-menu a{
60
60
text-decoration: none;
61
61
}
62
+ .main-menu a.active{
63
+ font-weight: bold;
64
+ }
62
65
.main-menu a:hover{
63
66
text-decoration: underline;
64
67
}
Original file line number Diff line number Diff line change 1
- import { createFlatData } from './_data'
2
1
import { useHeTree , sortFlatData } from "he-tree-react" ;
3
2
import { useState } from 'react' ;
4
3
5
4
export default function BasePage ( ) {
6
5
const keys = { idKey : 'id' , parentIdKey : 'parent_id' } ;
7
- const [ data , setdata ] = useState ( ( ) => sortFlatData ( createFlatData ( ) , keys ) ) ;
6
+ const [ data , setdata ] = useState ( ( ) => sortFlatData ( [
7
+ {
8
+ id : 1 ,
9
+ parent_id : null ,
10
+ name : "Root Category" ,
11
+ } ,
12
+ {
13
+ id : 2 ,
14
+ parent_id : 1 ,
15
+ name : "Technology" ,
16
+ } ,
17
+ {
18
+ id : 5 ,
19
+ parent_id : 2 ,
20
+ name : "Hardware" ,
21
+ } ,
22
+ {
23
+ id : 10 ,
24
+ parent_id : 5 ,
25
+ name : "Computer Components" ,
26
+ } ,
27
+ {
28
+ id : 4 ,
29
+ parent_id : 2 ,
30
+ name : "Programming" ,
31
+ } ,
32
+ {
33
+ id : 8 ,
34
+ parent_id : 4 ,
35
+ name : "Python" ,
36
+ } ,
37
+ {
38
+ id : 3 ,
39
+ parent_id : 1 ,
40
+ name : "Science" ,
41
+ } ,
42
+ {
43
+ id : 7 ,
44
+ parent_id : 3 ,
45
+ name : "Biology" ,
46
+ } ,
47
+ {
48
+ id : 6 ,
49
+ parent_id : 3 ,
50
+ name : "Physics" ,
51
+ } ,
52
+ ] , keys ) ) ;
8
53
const { renderHeTree } = useHeTree ( {
9
54
...keys ,
10
55
data,
@@ -14,7 +59,7 @@ export default function BasePage() {
14
59
{ node . name }
15
60
</ div > ,
16
61
} )
17
- return < div style = { { width : '300px' , border : '1px solid #ccc' , padding : '10px' } } >
18
- { renderHeTree ( ) }
62
+ return < div >
63
+ { renderHeTree ( { style : { width : '300px' , border : '1px solid #555' , padding : '20px' } } ) }
19
64
</ div >
20
65
}
Original file line number Diff line number Diff line change 1
- import { createTreeData } from './_data'
2
- import { useHeTree } from "../../lib/index" ;
1
+ import { useHeTree } from "he-tree-react" ;
3
2
import { useState } from 'react' ;
4
3
5
4
export default function BasePage ( ) {
6
- const [ data , setdata ] = useState ( createTreeData ) ;
5
+ const [ data , setdata ] = useState ( ( ) => [
6
+ {
7
+ id : 1 ,
8
+ name : "Root Category" ,
9
+ children : [
10
+ {
11
+ id : 2 ,
12
+ name : "Technology" ,
13
+ children : [
14
+ {
15
+ id : 5 ,
16
+ name : "Hardware" ,
17
+ children : [
18
+ {
19
+ id : 10 ,
20
+ name : "Computer Components" ,
21
+ children : [ ] ,
22
+ } ,
23
+ ] ,
24
+ } ,
25
+ {
26
+ id : 4 ,
27
+ name : "Programming" ,
28
+ children : [
29
+ {
30
+ id : 8 ,
31
+ name : "Python" ,
32
+ children : [ ] ,
33
+ } ,
34
+ ] ,
35
+ } ,
36
+ ] ,
37
+ } ,
38
+ {
39
+ id : 3 ,
40
+ name : "Science" ,
41
+ children : [
42
+ {
43
+ id : 7 ,
44
+ name : "Biology" ,
45
+ children : [ ] ,
46
+ } ,
47
+ {
48
+ id : 6 ,
49
+ name : "Physics" ,
50
+ children : [ ] ,
51
+ } ,
52
+ ] ,
53
+ } ,
54
+ ] ,
55
+ } ,
56
+ ] ) ;
7
57
const { renderHeTree } = useHeTree ( {
8
58
data,
9
59
dataType : 'tree' ,
@@ -14,6 +64,6 @@ export default function BasePage() {
14
64
</ div > ,
15
65
} )
16
66
return < div >
17
- { renderHeTree ( ) }
67
+ { renderHeTree ( { style : { width : '300px' , border : '1px solid #555' , padding : '20px' } } ) }
18
68
</ div >
19
69
}
You can’t perform that action at this time.
0 commit comments