TA的每日心情 | 衰 2021-2-2 11:21 |
---|
签到天数: 36 天 [LV.5]常住居民I
|
js方法:- //点击Ztree 实践 发送请求 7 S) V( J0 W! \3 N; y+ Z' ~0 X
- function querZtree(){
+ I# x9 n6 t: x; B; e g3 D - $.ajax({, c- y6 N* c9 P) ^2 X0 W. C1 g& I2 @
- url:'baseInfoAction_queryZtree.action',% @6 y" n+ q ~4 D6 P* e' K
- async:false,
6 m( E' `2 {* i2 \+ }+ s# G - data:{'time':(new Date()).toString()},$ ]: c4 |$ f1 e+ h3 c. r
- success:function(result){' n3 p0 B! d2 H6 c
- var array = eval(result);
" q4 A# C0 S( p8 P! D- _" G - var setting = { 3 i% |/ u% l: D5 o. Q( Z. ]+ h
- view: {
- a* z, x ]* o1 i2 y - showIcon: false,
6 n7 b2 f+ i3 ~ - showLine: false 8 L; v/ \1 H* u+ a2 Y' A
- }, 1 S9 }9 w/ W9 W; s/ U; q* y+ V+ _4 o
- callback : {7 n+ m* d7 v8 @& N
- onClick: zTreeOnClick//回调方法 用户点击 传参数
# X; c5 A7 y% `* e; Y- h - }1 W9 O; f# g1 Q! O% G# K6 p* b6 u$ F
- };0 ~8 S5 v+ A3 t) j
- $.fn.zTree.init($("#treeBox"), setting, array);//把数据放到 treeBox内4 y$ L C! V0 _$ j3 R8 b3 R" s
- }2 Y3 S% ^) R+ s
- });
; z, Y! i/ B# S/ e- o8 j+ q; e6 _ - }
复制代码 Ztree 回调方法:- //点击知识点 获取对象
7 v X6 ?) {1 y3 q! q( i - function zTreeOnClick(event, treeId, treeNode){
$ Q( y6 v! w' }6 T$ ` - alert(treeNode.name)
复制代码
) U7 i6 ~+ V& zstruts.xml 配置文件:! O9 }: F2 \+ Z0 { z3 S7 y& G. c) z
- <action name="baseInfoAction_*" method="{1}" class="com.53itstyle.web.baseInfo.action.BaseInfoAction">
. W! T% D9 q. @ - <result name="knowledge"></result>
% P4 D( H; K/ t% D7 o% j9 | - </action>
复制代码 Action 后台方法:# Y6 G# x, E( K7 ^% g
- public void queryZtree(){, j$ h( ~% f9 g: \
- try {
2 @ ^5 G# ] P+ n: l* m% q' e& s - JSONArray resultArray = new JSONArray();9 y* }0 T* o' k4 k8 J# b- z
- for(int i=0;i<4;i++){
2 ~1 y3 G/ b6 v5 e - JSONObject jsonObject = new JSONObject();$ Q, p/ x6 F, ~, e' }7 }
- jsonObject.put("name", "一级"+i);
7 h( k% T4 l) o+ s$ L - jsonObject.put("open", true);* g' |9 O9 v/ s2 R3 g3 A
- JSONArray typeArr = new JSONArray();, V1 D/ f% v9 P* _ c% \ J: |+ i
- for(int j=0;j<4;j++){
1 X6 Q9 o: {$ I3 D; a+ [& n/ n - JSONObject knObj = new JSONObject();1 k8 I' l7 G" f1 y9 P. I
- knObj.put("name", "二级"+j);5 S, @6 k; l X( q
- knObj.put("open", true);; T* x1 W; z6 C
- typeArr.put(knObj);
: Z/ i+ s+ H: K( t' g5 J - jsonObject.put("children", typeArr);3 t1 i' M& n* t3 Q2 l% P4 a7 o6 L" T
- }
/ P' w J3 E5 O7 ^ - resultArray.put(jsonObject);5 M' w, L. b/ T1 p- C
- }
' O# N/ F& o9 _% A% O - printMsgToClient(resultArray.toString());
/ B3 u" c. Q! v/ o- ~- G7 y - } catch (Exception e) {
# u3 x4 p. H+ \" v - e.printStackTrace();( A) q/ s4 U# e% @
- }% e+ Q. {' q# ] @/ N6 t
- }
复制代码 将结果返回给xmlRequest:( d8 a, \, e7 |0 y
- /**
: B$ A! n+ T c8 ?. b6 L - * 将结果返回给xmlRequest
- \& O* G7 `8 J3 P' h5 N. N - *
- e" S! s/ K) E" D* d* r& h - * @param s
8 H% ?$ Z/ Y& r8 L% o - * @param dictList% E, \0 \- O- s7 |4 k/ l
- * @return* I6 }% g9 Y' F$ Y
- * @throws Exception
4 f; m8 U ?+ J" f - */8 l3 x4 B( e9 y
- public void printMsgToClient(String result) throws Exception {
8 H5 u3 B) e7 v& y, ^9 T - getResponse().setCharacterEncoding("UTF-8");
: ^& ^. A7 a! J% Z" g0 m - PrintWriter out = getResponse().getWriter();1 _8 Z% G- p0 x: f( ]
- try {
- H! Y+ s, k& ` - out.print(result);
& w& z$ E1 z1 ~" ?0 P! \ - }catch (Exception e) {4 A7 y) E/ E6 h6 c4 Y( o
- e.printStackTrace();
5 A" b+ }. _8 W$ E) S. _. s" ~1 j - } finally {
% {; W. m; R7 O; Q - out.close();
% p4 a7 C% @* w/ D6 @0 ^+ T2 b/ X, d - }
5 g1 s8 M R% `" W9 l L& { - }
复制代码
7 |9 C/ f. l5 e1 x- [7 S- |, R' h
6 j2 x0 T% Z" c( y
$ |) B0 Q, M) N
* S3 e. }5 t* v! n& h
0 D8 ]& l: i2 N2 @0 t: K |
|