转(https://www.augsky.com/992.html)
选中父节点时,父节点下所有子节点也都全部选中
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 }