treeview-demo.js 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241
  1. $(function () {
  2. var defaultData = [
  3. {
  4. text: '父节点 1',
  5. href: '#parent1',
  6. tags: ['4'],
  7. nodes: [
  8. {
  9. text: '子节点 1',
  10. href: '#child1',
  11. tags: ['2'],
  12. nodes: [
  13. {
  14. text: '孙子节点 1',
  15. href: '#grandchild1',
  16. tags: ['0']
  17. },
  18. {
  19. text: '孙子节点 2',
  20. href: '#grandchild2',
  21. tags: ['0']
  22. }
  23. ]
  24. },
  25. {
  26. text: '子节点 2',
  27. href: '#child2',
  28. tags: ['0']
  29. }
  30. ]
  31. },
  32. {
  33. text: '父节点 2',
  34. href: '#parent2',
  35. tags: ['0']
  36. },
  37. {
  38. text: '父节点 3',
  39. href: '#parent3',
  40. tags: ['0']
  41. },
  42. {
  43. text: '父节点 4',
  44. href: '#parent4',
  45. tags: ['0']
  46. },
  47. {
  48. text: '父节点 5',
  49. href: '#parent5',
  50. tags: ['0']
  51. }
  52. ];
  53. var alternateData = [
  54. {
  55. text: '父节点 1',
  56. tags: ['2'],
  57. nodes: [
  58. {
  59. text: '子节点 1',
  60. tags: ['3'],
  61. nodes: [
  62. {
  63. text: '孙子节点 1',
  64. tags: ['6']
  65. },
  66. {
  67. text: '孙子节点 2',
  68. tags: ['3']
  69. }
  70. ]
  71. },
  72. {
  73. text: '子节点 2',
  74. tags: ['3']
  75. }
  76. ]
  77. },
  78. {
  79. text: '父节点 2',
  80. tags: ['7']
  81. },
  82. {
  83. text: '父节点 3',
  84. icon: 'glyphicon glyphicon-earphone',
  85. href: '#demo',
  86. tags: ['11']
  87. },
  88. {
  89. text: '父节点 4',
  90. icon: 'glyphicon glyphicon-cloud-download',
  91. href: '/demo.html',
  92. tags: ['19'],
  93. selected: true
  94. },
  95. {
  96. text: '父节点 5',
  97. icon: 'glyphicon glyphicon-certificate',
  98. color: 'pink',
  99. backColor: 'red',
  100. href: 'http://www.tesco.com',
  101. tags: ['available', '0']
  102. }
  103. ];
  104. var json = '[' +
  105. '{' +
  106. '"text": "父节点 1",' +
  107. '"nodes": [' +
  108. '{' +
  109. '"text": "子节点 1",' +
  110. '"nodes": [' +
  111. '{' +
  112. '"text": "孙子节点 1"' +
  113. '},' +
  114. '{' +
  115. '"text": "孙子节点 2"' +
  116. '}' +
  117. ']' +
  118. '},' +
  119. '{' +
  120. '"text": "子节点 2"' +
  121. '}' +
  122. ']' +
  123. '},' +
  124. '{' +
  125. '"text": "父节点 2"' +
  126. '},' +
  127. '{' +
  128. '"text": "父节点 3"' +
  129. '},' +
  130. '{' +
  131. '"text": "父节点 4"' +
  132. '},' +
  133. '{' +
  134. '"text": "父节点 5"' +
  135. '}' +
  136. ']';
  137. $('#treeview1').treeview({
  138. data: defaultData
  139. });
  140. $('#treeview2').treeview({
  141. levels: 1,
  142. data: defaultData
  143. });
  144. $('#treeview3').treeview({
  145. levels: 99,
  146. data: defaultData
  147. });
  148. $('#treeview4').treeview({
  149. color: "#428bca",
  150. data: defaultData
  151. });
  152. $('#treeview5').treeview({
  153. color: "#428bca",
  154. expandIcon: 'glyphicon glyphicon-chevron-right',
  155. collapseIcon: 'glyphicon glyphicon-chevron-down',
  156. nodeIcon: 'glyphicon glyphicon-bookmark',
  157. data: defaultData
  158. });
  159. $('#treeview6').treeview({
  160. color: "#428bca",
  161. expandIcon: "glyphicon glyphicon-stop",
  162. collapseIcon: "glyphicon glyphicon-unchecked",
  163. nodeIcon: "glyphicon glyphicon-user",
  164. showTags: true,
  165. data: defaultData
  166. });
  167. $('#treeview7').treeview({
  168. color: "#428bca",
  169. showBorder: false,
  170. data: defaultData
  171. });
  172. $('#treeview8').treeview({
  173. expandIcon: "glyphicon glyphicon-stop",
  174. collapseIcon: "glyphicon glyphicon-unchecked",
  175. nodeIcon: "glyphicon glyphicon-user",
  176. color: "yellow",
  177. backColor: "purple",
  178. onhoverColor: "orange",
  179. borderColor: "red",
  180. showBorder: false,
  181. showTags: true,
  182. highlightSelected: true,
  183. selectedColor: "yellow",
  184. selectedBackColor: "darkorange",
  185. data: defaultData
  186. });
  187. $('#treeview9').treeview({
  188. expandIcon: "glyphicon glyphicon-stop",
  189. collapseIcon: "glyphicon glyphicon-unchecked",
  190. nodeIcon: "glyphicon glyphicon-user",
  191. color: "yellow",
  192. backColor: "purple",
  193. onhoverColor: "orange",
  194. borderColor: "red",
  195. showBorder: false,
  196. showTags: true,
  197. highlightSelected: true,
  198. selectedColor: "yellow",
  199. selectedBackColor: "darkorange",
  200. data: alternateData
  201. });
  202. $('#treeview10').treeview({
  203. color: "#428bca",
  204. enableLinks: true,
  205. data: defaultData
  206. });
  207. $('#treeview11').treeview({
  208. color: "#428bca",
  209. data: defaultData,
  210. onNodeSelected: function (event, node) {
  211. $('#event_output').prepend('<p>您单击了 ' + node.text + '</p>');
  212. }
  213. });
  214. // $('#treeview11').on('nodeSelected', function (event, node) {
  215. // $('#event_output').prepend('<p>您单击了 ' + node.text + '</p>');
  216. // });
  217. $('#treeview12').treeview({
  218. data: json
  219. });
  220. });