58984f3f2c0fc0c98829207e26895fe952c30fd8.svn-base 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229
  1. <%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
  2. <%
  3. String path = request.getContextPath();
  4. %>
  5. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  6. <html xmlns="http://www.w3.org/1999/xhtml">
  7. <head>
  8. <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
  9. <title>多选下拉框</title>
  10. <!--框架必需start-->
  11. <script type="text/javascript" src="<%=path%>/libs/js/jquery.js"></script>
  12. <script type="text/javascript" src="<%=path%>/libs/js/language/cn.js"></script>
  13. <script type="text/javascript" src="<%=path%>/libs/js/framework.js"></script>
  14. <link href="<%=path%>/libs/css/import_basic.css" rel="stylesheet" type="text/css"/>
  15. <link rel="stylesheet" type="text/css" id="skin" prePath="<%=path%>/"/>
  16. <link rel="stylesheet" type="text/css" id="customSkin"/>
  17. <!--框架必需end-->
  18. <!-- 树组件start -->
  19. <script type="text/javascript" src="<%=path%>/libs/js/tree/ztree/ztree.js"></script>
  20. <link type="text/css" rel="stylesheet" href="<%=path%>/libs/js/tree/ztree/ztree.css"></link>
  21. <!-- 树组件end -->
  22. <!-- 树形下拉框start -->
  23. <script type="text/javascript" src="<%=path%>/libs/js/form/selectTree.js"></script>
  24. <!-- 树形下拉框end -->
  25. </head>
  26. <body>
  27. <div class="box1" panelWidth="800">
  28. <fieldset>
  29. <legend>注意</legend>
  30. 多选下拉框实际是树形下拉框的衍伸,属性直接继承树形下拉框。 这些示例与“树形下拉框”用法类似:<br/>
  31. 使用隐藏域,close事件, 禁用/启用,自定义图标,自定义节点展开/收缩时的图标,自定义尺寸(下拉框宽度和高度、文本框宽度),下拉框展开方向,可编辑,节点集成动态操作,表单重置。 请参考“树形下拉框”一节。<br/>
  32. </fieldset>
  33. <div class="height_15"></div>
  34. <fieldset>
  35. <legend>1、基本多选下拉框(本地数据)</legend>
  36. <p>使用本地数据时,除了可以添加数据到组件标签的data属性中,还可以使用本地数据动态设置data。参见:“树形下拉框”</p>
  37. <div class="selectTree" id="selectTree1" multiMode="true" noGroup="true" data='{"treeNodes":[{ "id":"1", "parentId":"0", "name":"员工1"},{ "id":"2", "parentId":"0", "name":"员工2"},{ "id":"3", "parentId":"0", "name":"员工3"},{ "id":"4", "parentId":"0", "name":"员工4"}]}'></div>
  38. <br/><input type="button" value="获取值" onclick="getValue()"/>
  39. </fieldset>
  40. <div class="height_15"></div>
  41. <fieldset>
  42. <legend>2、基本多选下拉框(远程数据)</legend>
  43. <div class="red">此示例由后台支持</div>
  44. <p>使用远程数据时,除了使用url,还可以使用url+参数,ajax请求然后动态设置data。参见:“树形下拉框”</p>
  45. <div class="selectTree" url="<%=path%>/form/getDepartmentList.action" multiMode="true" noGroup="true"></div>
  46. </fieldset>
  47. <div class="height_15"></div>
  48. <fieldset>
  49. <legend>3、树形多选下拉框(父节点不可选)</legend>
  50. <p>这里设置数据的父节点不可选,并且设置点击父节点展开子节点</p>
  51. <div class="selectTree" id="selectTree3" multiMode="true" keepDefaultStyle="true"></div>
  52. <br/>另外此处采用动态设置data方式获取数据。
  53. </fieldset>
  54. <div class="height_15"></div>
  55. <fieldset>
  56. <legend>4、树形多选下拉框(父节点作为单独的一项可选)</legend>
  57. <div class="red">此示例由后台支持</div>
  58. <p> 这里设置数据的父节点可选,并且不展开子节点。这样点击就会选中该节点,子节点与父节点无关。</p>
  59. <div class="selectTree" url="<%=path%>/getDepartmentsTree.action" multiMode="true"></div>
  60. <br/>另外此处采用url方式获取数据。
  61. </fieldset>
  62. <div class="height_15"></div>
  63. <fieldset>
  64. <legend>5、树形多选下拉框(点击父节点全选)</legend>
  65. <p>设置点击展开子节点,然后设置组件可全选属性。这样点击会展开并全选子节点。</p>
  66. 此示例全选后保留父节点的值。<br/>
  67. <div class="selectTree" id="selectTree5-1" multiMode="true" allSelectable="true" keepDefaultStyle="true"></div>
  68. <br/><br/>
  69. 此示例全选后不保留父节点的值。<br/>
  70. <div class="selectTree" id="selectTree5-2" multiMode="true" allSelectable="true" exceptParent="true" keepDefaultStyle="true"></div>
  71. </fieldset>
  72. <div class="height_15"></div>
  73. <fieldset>
  74. <legend>6、设置初始值</legend>
  75. <div class="selectTree" id="selectTree6" multiMode="true" selectedValue="11,12,21" data='{"treeNodes":[{"id":"1","parentId":"0","name":"部门部门部门部门部门部门部门部门1","nocheck":"true","clickExpand":"true","open":"true"},{"id":"11","parentId":"1", "name":"员工1"},{"id":"12","parentId":"1", "name":"员工2"},{"id":"13","parentId":"1", "name":"员工3"},{"id":"2","parentId":"0","name":"部门2","nocheck":"true","clickExpand":"true","open":"true"},{"id":"21","parentId":"2", "name":"员工4"}]}'></div>
  76. <br/><input type="button" value="获取值" onclick="getSelectValue()"/>
  77. </fieldset>
  78. <div class="height_15"></div>
  79. <fieldset>
  80. <legend>7、动态生成树形下拉框</legend>
  81. <div class="red">此示例由后台支持</div>
  82. <input type="button" value="点击生成(使用url)" style="width:120px;" id="testBtn" onclick="dynamicSelTreebox1()"/><br/><br/>
  83. <input type="button" value="点击生成(使用data)" style="width:120px;" id="testBtn2" onclick="dynamicSelTreebox2()"/>
  84. </fieldset>
  85. <div class="height_15"></div>
  86. <fieldset>
  87. <legend>8、动态修改树形下拉框</legend>
  88. <div class="selectTree" id="selectTree8" multiMode="true" data='{"treeNodes":[{"id":"1","parentId":"0","name":"部门1","nocheck":"true","clickExpand":"true","open":"true"},{"id":"11","parentId":"1", "name":"员工1"},{"id":"12","parentId":"1", "name":"员工2"},{"id":"13","parentId":"1", "name":"员工3"},{"id":"2","parentId":"0","name":"部门2","nocheck":"true","clickExpand":"true","open":"true"},{"id":"21","parentId":"2", "name":"员工4"}]}'></div>
  89. <br/><br/><input type="button" value="选中“员工1,员工4”" onclick="selectItem()" style="width:120px;"/>
  90. <input type="button" value="追加一项" onclick="appendItem()" style="width:120px;"/>
  91. <input type="button" value="移除“员工2”" onclick="removeItem()" style="width:120px;"/>
  92. </fieldset>
  93. <div class="height_15"></div>
  94. <fieldset>
  95. <legend>9、获得选中节点自定义属性</legend>
  96. <div class="selectTree" id="selectTree9" multiMode="true" data='{"treeNodes":[{ "id":"1", "parentId":"0", "name":"部门1", "open": "true","myFlag":"部门1-自定义属性"},{ "id":"11", "parentId":"1", "name":"员工1","myFlag":"员工1-自定义属性"},{ "id":"12", "parentId":"1", "name":"员工2","myFlag":"员工2-自定义属性"},{ "id":"13", "parentId":"1", "name":"员工3","myFlag":"员工3-自定义属性"},{ "id":"2", "parentId":"0", "name":"部门2", "open": "true","myFlag":"部门2-自定义属性"},{ "id":"21", "parentId":"2", "name":"员工4","myFlag":"员工4-自定义属性"}]}'></div>
  97. </fieldset>
  98. <div class="height_15"></div>
  99. <fieldset>
  100. <legend>10、节点异步加载</legend>
  101. <div class="red">此示例由后台支持</div>
  102. <div class="selectTree" asyncMode="true" url="<%=path%>/getAsyncTree.action" multiMode="true"></div>
  103. </fieldset>
  104. <div class="height_15"></div>
  105. </div>
  106. <script type="text/javascript">
  107. var zNodes2 ={"treeNodes":[
  108. { id:1, parentId:0, name:"部门1", nocheck:true, clickExpand:true},
  109. { id:11, parentId:1, name:"员工1"},
  110. { id:12, parentId:1, name:"员工2"},
  111. { id:13, parentId:1, name:"员工3"},
  112. { id:2, parentId:0, name:"部门2", nocheck:true, clickExpand:true},
  113. { id:21, parentId:2, name:"员工4"}
  114. ]};
  115. var zNodes3 ={"treeNodes":[
  116. { id:1, parentId:0, name:"部门1", clickExpand:true},
  117. { id:11, parentId:1, name:"员工1"},
  118. { id:12, parentId:1, name:"员工2"},
  119. { id:13, parentId:1, name:"员工3"},
  120. { id:2, parentId:0, name:"部门2", clickExpand:true},
  121. { id:21, parentId:2, name:"员工4"}
  122. ]};
  123. function initComplete(){
  124. //赋给data
  125. $("#selectTree3").data("data",zNodes2);
  126. $("#selectTree3").render();
  127. //赋给data
  128. $("#selectTree5-1").data("data",zNodes3);
  129. $("#selectTree5-1").render();
  130. $("#selectTree5-2").data("data",zNodes3);
  131. $("#selectTree5-2").render();
  132. //数据自定义属性
  133. $("#selectTree9").bind("change",function(){
  134. if(!$(this).attr("relValue")){
  135. top.Dialog.alert("没有选择节点");
  136. }else{
  137. var nodes=$(this).data("selectedNodes");
  138. var values=[];
  139. for(var i=0;i<nodes.length;i++){
  140. values.push(nodes[i].myFlag);
  141. }
  142. top.Dialog.alert(values.join(","))
  143. }
  144. })
  145. }
  146. //获取值
  147. function getValue(){
  148. top.Dialog.alert("选中节点文本:"+$("#selectTree1").attr("relText")+"<br/>选中节点id:"+$("#selectTree1").attr("relValue"));
  149. }
  150. //获取选择值
  151. function getSelectValue(){
  152. top.Dialog.alert("选中节点文本:"+$("#selectTree6").attr("relText")+"<br/>选中节点id:"+$("#selectTree6").attr("relValue"));
  153. }
  154. //动态生成树形下拉框(使用url)
  155. function dynamicSelTreebox1(){
  156. //获取远程数据
  157. var $selTree = $('<div class="selectTree" multiMode="true"></div>');
  158. //设置url属性
  159. $selTree.attr("url","<%=path%>/getDepartmentsTree.action");
  160. //设置选中项
  161. $selTree.attr("selectedValue","11,12,23");
  162. //将下拉框加到按钮的后面
  163. $("#testBtn").after($selTree);
  164. $("#testBtn").after("<br/>");
  165. //渲染树形下拉框
  166. $selTree.render();
  167. }
  168. //动态生成树形下拉框(使用data)
  169. function dynamicSelTreebox2(){
  170. //获取远程数据
  171. $.post("<%=path%>/getDepartmentsTree.action",{},function(result){
  172. var $selTree = $('<div class="selectTree" multiMode="true"></div>');
  173. //赋给data属性
  174. $selTree.attr("data",JSON.stringify(result));
  175. //设置选中项
  176. $selTree.attr("selectedValue","11,12,23");
  177. //将下拉框加到按钮的后面
  178. $("#testBtn2").after($selTree);
  179. $("#testBtn2").after("<br/>");
  180. //渲染树形下拉框
  181. $selTree.render();
  182. },"json");
  183. }
  184. //动态选中项
  185. function selectItem(){
  186. $("#selectTree8").setValue("11,21");
  187. }
  188. //追加一项
  189. function appendItem(){
  190. $("#selectTree8").addItem({id:100, parentId:2, name:"员工5"});
  191. }
  192. //移除项
  193. function removeItem(){
  194. $("#selectTree8").removeItem("12");
  195. }
  196. </script>
  197. </body>
  198. </html>