TA的每日心情 | 衰 2021-2-2 11:21 |
---|
签到天数: 36 天 [LV.5]常住居民I
|
js方法:- //点击Ztree 实践 发送请求
8 H8 V# A& M* l - function querZtree(){6 {' ^4 |) j5 o" M. J
- $.ajax({
" v* r7 f2 ~; g0 C! d/ u% f - url:'baseInfoAction_queryZtree.action',' I0 U. e4 n5 X! C
- async:false, n7 a Q+ H% T7 F' e: Y: K
- data:{'time':(new Date()).toString()},
' s) A' V5 M) Y5 `% l& t# |# i - success:function(result){, k& u7 W! T, D9 s+ r: j+ @
- var array = eval(result);" ~# W# `+ z8 b+ y4 Y$ k( a
- var setting = {
6 r" H# h; l: y- m" A6 x - view: {
9 s; S2 x' J9 i! Z - showIcon: false,
& \5 ~) T4 Z* n3 M7 J+ _; ?" ^& n - showLine: false 0 S3 t9 p# u! r; L5 k2 m8 j
- }, 8 C) ^; L5 c2 v# F- x2 x
- callback : {+ J0 }0 _: L0 N6 O
- onClick: zTreeOnClick//回调方法 用户点击 传参数
) H; l; L' _. g* G - }
* i6 d/ f% o! h; Q9 }2 T - };) A- k: W0 P1 h+ W2 |
- $.fn.zTree.init($("#treeBox"), setting, array);//把数据放到 treeBox内- |; f/ c$ z7 n
- }
0 ]7 ? x5 k) P1 w' Q# W9 h7 l/ \! b - });& r$ X% Z+ n! t: D3 A, M
- }
复制代码 Ztree 回调方法:- //点击知识点 获取对象
0 y/ H/ L' k, Q1 N% I - function zTreeOnClick(event, treeId, treeNode){
7 t4 b/ J1 f5 H3 [! I - alert(treeNode.name)
复制代码
- q; R7 X; v; G' k5 ?) hstruts.xml 配置文件:+ o4 T; C3 ^% @& [! B; C
- <action name="baseInfoAction_*" method="{1}" class="com.53itstyle.web.baseInfo.action.BaseInfoAction">
. X) j' Z+ ~$ c' C4 x - <result name="knowledge"></result>9 y$ h$ P7 D0 v R( d' [# B
- </action>
复制代码 Action 后台方法:7 o* l8 E, c! z$ }, n$ H6 ?
- public void queryZtree(){
& M0 C7 j% T) k+ I( } - try {' R) V! t' G1 Q4 i
- JSONArray resultArray = new JSONArray();
# D. Z9 h3 t' J% ` ]: G* i - for(int i=0;i<4;i++){
, k, } Q( f6 r- b - JSONObject jsonObject = new JSONObject();
4 X, V) D2 c) C( `! p - jsonObject.put("name", "一级"+i);
" `8 h: a& s1 r, i - jsonObject.put("open", true);
5 S7 b* p% V0 d3 `# |: @; y1 i! T - JSONArray typeArr = new JSONArray(); F0 v/ E# @7 o4 V1 D8 Y
- for(int j=0;j<4;j++){
( t' l( G& L. K( Y& s1 Z - JSONObject knObj = new JSONObject();) h D9 @1 U. g L( \
- knObj.put("name", "二级"+j);+ L$ e$ b. L# [4 u+ @/ T
- knObj.put("open", true);, E' B) S$ P" d( y- A
- typeArr.put(knObj);0 o+ D2 q" x2 Q, S# X% p0 ~
- jsonObject.put("children", typeArr);
2 {4 n k, ]& P7 i% l, o+ j7 T - }
8 r2 X% r$ B/ n! ~; u) D - resultArray.put(jsonObject);
# h: J6 h' D0 ]+ r' g - }
, F( i! z" [5 H, i0 w$ n - printMsgToClient(resultArray.toString());* [0 C7 e2 k: d5 {/ D
- } catch (Exception e) {* r9 Z* ?% P! h7 S. k
- e.printStackTrace();- a+ T+ z+ e6 ]( j6 _8 L9 C
- }
- V* w4 z$ h5 s ~8 A# J - }
复制代码 将结果返回给xmlRequest:- Z5 M( s Y0 q- [3 }) D
- /**" @& |& ]2 S( ? l8 Q* M3 z
- * 将结果返回给xmlRequest# \/ ~: H- ^: c1 a
- * 4 V0 w1 _" b: U3 r
- * @param s
6 @% E8 N* j+ A+ `# M' U5 O - * @param dictList
* g- y- v0 z# q | - * @return
& ^, Z( l- r7 K8 i. j - * @throws Exception
' t2 y# U' f: ?2 j - */
: H1 g) d( Q& Z' I) {) ^4 n9 b - public void printMsgToClient(String result) throws Exception {6 B4 K$ k. R* n; k M& A
- getResponse().setCharacterEncoding("UTF-8");
: f. D7 N i* p. o - PrintWriter out = getResponse().getWriter();% \2 ]5 ^; b( L# e8 b
- try {5 ^+ D A3 E4 ~! L! y
- out.print(result);
, p' K. z+ b/ x1 B& v - }catch (Exception e) {- _8 @- H1 [0 }+ B8 O% W- L T
- e.printStackTrace();
+ ]- j/ x0 ] _- j - } finally {/ T7 u, k, Q' k5 ^( ~
- out.close();
! H4 x0 F: L+ A - }' ~% {5 W0 z" p& J
- }
复制代码
* |0 t' l3 v% j9 N/ l' n' O4 [- c9 Y5 J0 R' S8 Q ]* o- }
7 K1 D, T3 w, w
1 c, m3 w# `6 O$ z0 e3 ?
( f1 S- O, Z( `* _7 T$ O# [5 t |
|