TA的每日心情 | 衰 2021-2-2 11:21 |
|---|
签到天数: 36 天 [LV.5]常住居民I
|
js方法:- //点击Ztree 实践 发送请求 ; k6 E* r$ z# g. }
- function querZtree(){. ^* u6 F3 u8 Z2 G' D/ b+ j3 [
- $.ajax({
3 g; W- E/ ^1 h+ _9 T - url:'baseInfoAction_queryZtree.action',
; c7 E, W |; ]8 u - async:false,
! p" g& Z. k, M* S) z& T5 z7 |' b) g - data:{'time':(new Date()).toString()},$ i/ |$ Z: }/ O8 z; j
- success:function(result){$ c: V% g) g3 d# y8 w
- var array = eval(result);
0 X/ Q" b: K* x' s - var setting = {
: J+ _, a% E1 c9 J$ I& V - view: {
( P1 J: E9 O" n - showIcon: false,
# n, P2 G/ d9 a) H( T) z! P - showLine: false + v- G) g# t" ]9 j& }" A/ G
- },
3 @# m4 f- V8 m% u$ J" K5 [ - callback : {5 Y9 g6 ^% z& M9 Y$ {( }
- onClick: zTreeOnClick//回调方法 用户点击 传参数
8 i& y! B! U& z - }; m& M- c. T" Q2 M1 ~" X% b
- };6 f+ u) [* \% \3 a
- $.fn.zTree.init($("#treeBox"), setting, array);//把数据放到 treeBox内
+ X. u3 b' R. ?. _ - }( J1 `& m6 w. p9 h/ |% ~- P
- });
* `% `6 B1 p. {+ _2 Y0 z - }
复制代码 Ztree 回调方法:- //点击知识点 获取对象
' k. W; ~5 E, D - function zTreeOnClick(event, treeId, treeNode){0 x" I' ]6 S0 J. q0 |1 z6 R2 W
- alert(treeNode.name)
复制代码 $ t3 e0 v' k a/ F1 W
struts.xml 配置文件:
: O4 ~! P& e4 f- <action name="baseInfoAction_*" method="{1}" class="com.53itstyle.web.baseInfo.action.BaseInfoAction">( l7 Y3 ^$ }' L7 U/ }
- <result name="knowledge"></result>4 R; x0 U/ d: N! [. I6 m
- </action>
复制代码 Action 后台方法:/ J2 V7 Q. p* i: M ^
- public void queryZtree(){/ g3 W2 j7 N) r8 Q5 s; |
- try {* h; [' ?: r7 a, c) I7 {. @
- JSONArray resultArray = new JSONArray();; B M$ P% c7 ]+ K
- for(int i=0;i<4;i++){
7 u9 K4 x" }0 D$ v$ M - JSONObject jsonObject = new JSONObject();' p: o1 [) D: W+ f: e M7 e7 r
- jsonObject.put("name", "一级"+i);
2 j+ C- l( v4 C( \/ m# L - jsonObject.put("open", true);
Q1 t5 K% @, g, q5 b( { - JSONArray typeArr = new JSONArray();/ x- e; ^- \) ^* A3 D
- for(int j=0;j<4;j++){2 F: V% G/ ~* V- O# _
- JSONObject knObj = new JSONObject();
/ i' K) z1 p% y# O( J0 a - knObj.put("name", "二级"+j);
% N/ p7 g; {$ C) C - knObj.put("open", true);
$ t* t( J j8 g) ~6 n - typeArr.put(knObj);
( s v; T% _% i - jsonObject.put("children", typeArr);* _! ?' G+ n7 b* A1 e0 @
- }
8 i3 G! V4 ?$ V( g" a3 s( H% ? - resultArray.put(jsonObject);
7 e$ a9 \+ Y% ^; E5 L& p# t - }
* \6 k$ q- L$ r$ Y- G o/ r - printMsgToClient(resultArray.toString());0 }1 O [. \* o' }: U/ e+ D& |
- } catch (Exception e) {! z% _+ t( N* ^
- e.printStackTrace();
7 e1 [# n+ X+ c1 s - }
3 W* J$ @. T2 R2 Y4 ? - }
复制代码 将结果返回给xmlRequest: Y" `. B+ L% b1 Y, B1 ? J+ M
- /**
9 x, d; K' j) p5 [# i/ Z - * 将结果返回给xmlRequest5 J( j0 ~* ?' N0 o& K
- * 5 Z* r) g! T! J) `' B$ G% V. q
- * @param s
b5 l! R" B5 {1 G' T - * @param dictList; e, \( A2 m* i. [, y
- * @return
% ?2 x+ P: z0 i, ~) J" | - * @throws Exception
6 e( A9 A+ k4 C5 j- K; N2 S - */" A! K; y, D$ ]& Q4 A' p
- public void printMsgToClient(String result) throws Exception {
3 s# C2 m: ~: @" d( r - getResponse().setCharacterEncoding("UTF-8");, ~6 A% \6 M! Y1 C2 t
- PrintWriter out = getResponse().getWriter();
% G ^/ O5 R* F" Z: c4 ~/ ^ - try {0 j; q8 G$ z! u( E9 z! ]
- out.print(result);) [' K' g1 a& O
- }catch (Exception e) {2 P/ v- _1 h. V$ F
- e.printStackTrace();
. u: h# g8 _. g5 z2 E. F - } finally {
' X/ c* k6 k K2 O5 ` - out.close();
" d; x2 }; ^, s( s6 v5 \, t - }7 b- a6 N- C3 h. f! k1 ^1 e
- }
复制代码
5 A. Y. I+ n4 o3 h Q j3 [/ L" B9 m& j1 v8 j- F
# P1 W/ n1 C9 u* c z$ R2 ]3 y3 [
, D& U4 k4 r9 |' p& f: L4 Z
$ }7 f8 n* c J0 {& \, h |
|