转(https://www.augsky.com/992.html)

bootstrap-treeview 如何实现全选父节点下所有子节点及反选

 

 

 

 

 

 

 

选中父节点时,父节点下所有子节点也都全部选中

1,HTML代码

1 <h2>TreeView Checkable</h2>
2 <div id="treeview-checkable"></div>

2,Json数据

 1  function getTvStateData() {
 2             var defaultData = [
 3                 {
 4                     text: 'Parent 1',
 5                     href: '#parent1',
 6                     tags: ['4'],
 7                     state: {
 8                         checked: true
 9                     },
10                     nodes: [
11                         {
12                             text: 'Child 1',
13                             href: '#child1',
14                             tags: ['2'],
15                             nodes: [
16                                 {
17                                     text: 'Grandchild 1',
18                                     href: '#grandchild1',
19                                     tags: ['0']
20                                 },
21                                 {
22                                     text: 'Grandchild 2',
23                                     href: '#grandchild2',
24                                     tags: ['0']
25                                 }
26                             ]
27                         },
28                         {
29                             text: 'Child 2',
30                             href: '#child2',
31                             tags: ['0']
32                         }
33                     ]
34                 },
35                 {
36                     text: 'Parent 2',
37                     href: '#parent2',
38                     tags: ['0'],
39                     nodes: [
40                         {
41                             text: 'Child 1',
42                             href: '#child1',
43                             tags: ['2'],
44                             nodes: [
45                                 {
46                                     text: 'Grandchild 1',
47                                     href: '#grandchild1',
48                                     tags: ['0']
49                                 },
50                                 {
51                                     text: 'Grandchild 2',
52                                     href: '#grandchild2',
53                                     tags: ['0']
54                                 }
55                             ]
56                         },
57                         {
58                             text: 'Child 2',
59                             href: '#child2',
60                             tags: ['0']
61                         }
62                     ]
63                 },
64                 {
65                     text: 'Parent 3',
66                     href: '#parent3'
67                 },
68                 {
69                     text: 'Parent 4',
70                     href: '#parent4',
71                     tags: ['0']
72                 },
73                 {
74                     text: 'Parent 5',
75                     href: '#parent5',
76                     tags: ['0']
77                 }
78             ];
79 
80             return defaultData;
81         }
View Code

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-10-06
  • 2022-12-23
  • 2021-12-28
  • 2021-10-08
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-11-20
  • 2021-12-15
  • 2022-12-23
相关资源
相似解决方案