TA的每日心情 | 衰 2021-2-2 11:21 |
---|
签到天数: 36 天 [LV.5]常住居民I
|
js方法:- //点击Ztree 实践 发送请求
5 i1 k; K$ x$ f, C0 N - function querZtree(){
& [0 C7 h" L6 h/ X. y - $.ajax({
7 Y: A1 }6 T. G! I, Z- T - url:'baseInfoAction_queryZtree.action',
+ E! x+ w2 C, o1 e1 d( q9 C( I - async:false,
# e1 {! z1 g8 g. g# i0 |" J, ? - data:{'time':(new Date()).toString()},
( n0 d$ j4 r& p - success:function(result){1 ^4 `, Q# @0 A
- var array = eval(result);. \: r: A% C) r& |3 `. I+ y
- var setting = {
1 f9 m7 |, s+ y: o - view: { . g2 Y. z& ], X: Q0 }+ _2 ^* w
- showIcon: false, # N6 I7 f0 | ]( d$ d4 m1 E, p
- showLine: false % f4 R0 z2 x `' ?
- },
% v6 W% {% w1 y - callback : {
% g& v: X2 X5 l6 p3 F+ @ - onClick: zTreeOnClick//回调方法 用户点击 传参数% G g/ W2 p) k# n2 l
- }
4 V; P* o' z- `, L/ ]! H - };# h* h5 @, ?( T. F
- $.fn.zTree.init($("#treeBox"), setting, array);//把数据放到 treeBox内8 i$ l3 l& B* a- [* P; k [& u
- }/ F' Y, l7 ]6 z/ J" ?
- });' I4 Y6 l" Y8 Q7 D
- }
复制代码 Ztree 回调方法:- //点击知识点 获取对象 $ e6 L' J% x0 {4 B Z3 D
- function zTreeOnClick(event, treeId, treeNode){
7 h; f' q l. a% G9 p - alert(treeNode.name)
复制代码
, l& e& H; D8 ?# q' w+ L- ~struts.xml 配置文件:' T$ X! m: [8 p3 d
- <action name="baseInfoAction_*" method="{1}" class="com.53itstyle.web.baseInfo.action.BaseInfoAction">
$ }5 J1 N$ ?; ]8 F% V( I+ Y - <result name="knowledge"></result>% m4 }3 |) B6 G2 t) K
- </action>
复制代码 Action 后台方法:
, Q5 E+ K# l: W; r% p. } t- public void queryZtree(){* o0 g3 ?5 Z) m/ ^8 j6 f
- try {5 c; I: g& t/ z/ o3 |* I
- JSONArray resultArray = new JSONArray();
/ n5 m* o$ T4 t' x. ` - for(int i=0;i<4;i++){1 }) y" q* E. L, F7 t# u9 F
- JSONObject jsonObject = new JSONObject();
) O1 _: E9 L& p/ v' _9 n; d: { - jsonObject.put("name", "一级"+i);
& a- c3 L5 I/ _1 }' J - jsonObject.put("open", true);' o# [$ w- g) }8 v' N$ {
- JSONArray typeArr = new JSONArray();
' d% u9 y! k! A @; G: o - for(int j=0;j<4;j++){
+ }( b$ L( j ?8 B2 o - JSONObject knObj = new JSONObject();
9 r k+ C, N; p/ u. [2 z - knObj.put("name", "二级"+j);
( ^. J' d$ N j$ {- [ - knObj.put("open", true);; m4 H" p6 J8 h; x5 n
- typeArr.put(knObj);! M5 N+ s: A9 w9 Z' D1 K8 _1 c
- jsonObject.put("children", typeArr);
$ d3 K6 d3 ^' h/ j% v - }
/ R# r/ A I/ [' s3 q& a - resultArray.put(jsonObject);
1 ?" p9 L) f U f, Q - }, Q3 g+ F$ B+ j" b
- printMsgToClient(resultArray.toString());
* F. d! k$ _3 h+ e2 u - } catch (Exception e) {
9 p% v ^2 h9 b5 d! A; Z$ A- m - e.printStackTrace();
( N. y2 P( `3 s, z - }
9 }: U5 G, t4 G! L - }
复制代码 将结果返回给xmlRequest:
* u2 ~3 I8 t( s _* Z- /**
% Y2 P& r" P- X - * 将结果返回给xmlRequest* e- p# |; R. y9 N' u
- * - g7 ^% J# a; B' ?: e1 Y7 ~6 [
- * @param s0 U* V! m+ m2 c4 O; l' ?
- * @param dictList
& s/ O% f. T4 ~) R3 @0 O* Y# m6 c - * @return
% ?4 x1 n* K; z* Z3 t9 Y0 g' L - * @throws Exception
9 ?/ u/ v% I u0 X4 j: P - */
7 @2 j' Z7 [7 |% X @0 | - public void printMsgToClient(String result) throws Exception {
# |% J0 ?, m0 [* q# Q! \ - getResponse().setCharacterEncoding("UTF-8");" v# U( K( L" n4 W1 }
- PrintWriter out = getResponse().getWriter();' o% H, F1 ]# b0 R8 n5 l, P
- try {* ?( N' S. b- {2 X/ H
- out.print(result);! \: d# _3 ~% `6 U4 O& t- ]* \
- }catch (Exception e) {
$ |+ w8 c1 N, I9 z' o% T, s; p - e.printStackTrace();7 |$ x \" F# |. o: V
- } finally {1 G! Q4 h) f0 o8 v$ R, }" c1 u
- out.close();1 D0 _4 D# s$ |+ ~6 _$ S+ e/ t
- }4 K2 ]5 K9 U& }3 h
- }
复制代码 , \* M0 s) T& ?& T9 `
7 ]2 Z0 H4 m1 K6 Q, ?
& u# u3 D s5 m; @$ W6 H' _. n
! c' }7 t J2 K. L7 U5 {3 S
9 X, c& k5 G: j1 |8 w |
|