TA的每日心情 | 衰 2021-2-2 11:21 |
---|
签到天数: 36 天 [LV.5]常住居民I
|
js方法:- //点击Ztree 实践 发送请求
% Q4 Z8 g' L# ]1 M - function querZtree(){
9 `, E# D! I$ b; i - $.ajax({7 [# z4 A/ c* F2 O; q
- url:'baseInfoAction_queryZtree.action',4 r. c" R' H: ?$ |7 T: p
- async:false,
% b+ P4 _5 b7 D" w: h - data:{'time':(new Date()).toString()},
+ f6 y+ F, l+ |- W b6 ] - success:function(result){
, k6 _0 K/ }/ Q) R7 @% A { u - var array = eval(result);
) F$ p- K2 o8 V- X1 H# S - var setting = { " h X6 v* n# _; O; X) l, T4 y
- view: { % ] J* y4 L+ @* M1 w
- showIcon: false,
5 L5 s. j- j# _0 n - showLine: false
L' V' I8 @$ O! O$ X - }, 8 G( _/ O% _3 _ E& i& }. x! z3 F
- callback : {
2 x* U& X- o" d& ^2 F9 A - onClick: zTreeOnClick//回调方法 用户点击 传参数% [. T) J9 O8 o9 L1 t) h5 N* E
- }
3 X+ w& a4 b- N1 W, l- P* X - };7 L6 f" x! ?4 x5 P+ O
- $.fn.zTree.init($("#treeBox"), setting, array);//把数据放到 treeBox内* S* x/ y5 ~1 O# T/ \6 V
- }
) n5 a' y' G1 @& K2 ]8 P8 n - });# x8 q, L- [4 y/ O" R: c" A
- }
复制代码 Ztree 回调方法:- //点击知识点 获取对象
9 [: B" W9 {* ^: g - function zTreeOnClick(event, treeId, treeNode){3 _# e) _0 ~9 w+ u. t' p( T& w
- alert(treeNode.name)
复制代码 ! }. j$ R7 h& R' S9 K
struts.xml 配置文件:
* ^1 W. W7 ?4 o5 d" q$ u* r% [- <action name="baseInfoAction_*" method="{1}" class="com.53itstyle.web.baseInfo.action.BaseInfoAction">
; m% z0 q. ?; z+ w+ C# y4 _8 J- N# ] - <result name="knowledge"></result>
9 w' g$ H. v: L4 q' S - </action>
复制代码 Action 后台方法:0 ^$ L! C' t/ n. A
- public void queryZtree(){
+ [8 f5 u" X9 M+ [ - try {
5 r% U& F/ n( I7 s% D - JSONArray resultArray = new JSONArray();" |- k' _- q) x3 ~
- for(int i=0;i<4;i++){. F/ C1 f: i& _) J! W
- JSONObject jsonObject = new JSONObject();
9 x4 @4 }; E( L - jsonObject.put("name", "一级"+i);
3 c7 U3 T- \; u - jsonObject.put("open", true);- t9 w/ E% u$ W+ J' m3 i
- JSONArray typeArr = new JSONArray();, T3 ?9 ?6 }5 C0 C3 o" J! t
- for(int j=0;j<4;j++){
$ ?' m2 b2 ^$ `' l Q - JSONObject knObj = new JSONObject();
, B0 @. |8 m8 E, ]7 l - knObj.put("name", "二级"+j);
3 \- @3 P) o9 C5 ~& c, ]7 W" [ - knObj.put("open", true);
' ]* u; C4 l0 E+ E* R* w. N4 D - typeArr.put(knObj);
0 a) C1 f5 ?4 U& s0 r) Y - jsonObject.put("children", typeArr);/ B4 K6 Y4 Q( i# N! o6 s
- }
! Q. Q8 N x$ D/ e - resultArray.put(jsonObject);
+ A) F; j3 G& f" v, h: |% N; l - }
8 V- }) z* G5 X$ X8 N - printMsgToClient(resultArray.toString());
4 L D9 l. g0 P8 ]4 ^ - } catch (Exception e) {5 v! a( W/ ~3 F
- e.printStackTrace();
6 B& z+ _9 i( l' E& B$ K5 N5 p - }
! e# w1 L$ g& B! x( b( }" g - }
复制代码 将结果返回给xmlRequest:
; k+ ~5 s- A U2 ~; ^, V3 J- /**8 H: Y* s* X9 Y6 g2 ^: i# q2 i$ {; h
- * 将结果返回给xmlRequest/ ~) X( T |% q& F4 R! e
- * ; _3 A% R4 T9 l' e9 N1 i6 O
- * @param s$ I b" i1 |: W) j* U \* B4 x
- * @param dictList
" h4 z' ]' J( |6 E - * @return
* x& w4 c# Q- U; z2 a - * @throws Exception
5 ]8 e8 ?% M" l' M$ ~ - *// O6 F" Q' E2 q& o
- public void printMsgToClient(String result) throws Exception {! ^& k7 C7 X ?2 E
- getResponse().setCharacterEncoding("UTF-8");
2 F% K' Q& T, D1 \6 q% p - PrintWriter out = getResponse().getWriter();+ c0 _2 l+ w! o# j, N
- try {
3 B; _% C* U0 t4 C: I& i+ } - out.print(result);3 Z, w$ d1 t) v2 Z! t
- }catch (Exception e) {. n- N3 t7 P6 D. l" @/ p% V: J
- e.printStackTrace();
1 T/ b% o0 h3 T& t - } finally {3 r# O r$ X5 f$ |6 O# b
- out.close();
; J: v: Z" w, j4 }5 `7 A! @ - }
. U, u; n; a, |$ B2 D - }
复制代码
- W( L% {5 [5 q7 K; n4 }* d/ c
2 o8 @5 l# Y8 ?6 T$ S5 q- h
9 l& L: Z/ s3 V+ y
) p: p& A' o/ Y" k
A% K! j. `; c/ n& B |
|