1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
|
//为站点添加onchange事件
Ext.getCmp('_s_combobox_peSite_siteName').on('change',function(e,id){
getList(id ,'/entity/teaching/electiveManage_ajaxGetTraining.action?siteId='+id , '_s_combobox_peTraining_trainingName');
});
//为培训添加onchange事件
Ext.getCmp('_s_combobox_peTraining_trainingName').on('change',function(e,id){
getList(id ,'/entity/teaching/electiveManage_ajaxGetCourse.action?trainId='+id , '_s_combobox_peTchCourse_courseName');
});
//为站点添加onfocus事件,清除培训、课程下拉框中的值
Ext.getCmp('_s_combobox_peSite_siteName').on('focus',function(e,id){
_s_combobox_peTraining_trainingName.clearValue();
_s_combobox_peTchCourse_courseName.clearValue();
});
//为培训添加onfocus事件,清除课程下拉框中的值
Ext.getCmp('_s_combobox_peTraining_trainingName').on('focus',function(e,id){
Ext.getCmp('_s_combobox_peTchCourse_courseName').clearValue();
});
function getList(id,url,target){
Ext.Ajax.request({
url:url,
method:'GET',
disableCaching:true,
callback:function(option,success,response){
if(success){
var recordsData = eval(response.responseText);
if(target=='_s_combobox_peTraining_trainingName'){
_s_combobox_peTraining_trainingName.store.removeAll();
_s_combobox_peTchCourse_courseName.store.removeAll();
_s_combobox_peTraining_trainingName.store.loadData(recordsData);
}else if(target='_s_combobox_peTchCourse_courseName'){
_s_combobox_peTchCourse_courseName.store.removeAll();
_s_combobox_peTchCourse_courseName.store.loadData(recordsData);
}
}
}
});
}
|
Action里面的方法
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
|
//站点 ----级联查询 课程
public
String
ajaxGetTraining(){
DetachedCriteria dc = DetachedCriteria.forClass(PeTraining.
class
);
dc.createCriteria(
"peSite"
,
"peSite"
)
.add(Restrictions.eq(
"id"
,
this
.getSiteId()));
dc.addOrder(Order.asc(
"name"
));
try
{
trainList =
this
.getGeneralService().getList(dc);
}
catch
(EntityException e) {
e.printStackTrace();
}
StringBuffer temp =
new
StringBuffer();
temp.append(
"["
);
for
(
int
i =
0
; i < trainList.size(); i++) {
temp.append(
"['"
);
temp.append(trainList.
get
(i).getId());
temp.append(
"','"
);
temp.append(trainList.
get
(i).getName());
temp.append(
"']"
);
if
(i!=trainList.size()-
1
){
temp.append(
","
);
}
}
temp.append(
"]"
);
this
.setAjaxResult(temp.toString());
return
"ajaxcheck"
;
}
//站点 ----级联查询 培训
public
String
ajaxGetCourse(){
DetachedCriteria dc = DetachedCriteria.forClass(PrTrainingCourse.
class
);
dc.createCriteria(
"peTraining"
,
"peTraining"
)
.add(Restrictions.eq(
"id"
,
this
.getTrainId()));
dc.createCriteria(
"peTchCourse"
,
"peTchCourse"
).addOrder(Order.desc(
"pubTime"
));
try
{
courseList =
this
.getGeneralService().getList(dc);
}
catch
(EntityException e) {
e.printStackTrace();
}
StringBuffer temp =
new
StringBuffer();
temp.append(
"["
);
for
(
int
i =
0
; i < courseList.size(); i++) {
temp.append(
"['"
);
temp.append(courseList.
get
(i).getPeTchCourse().getId());
temp.append(
"','"
);
temp.append(courseList.
get
(i).getPeTchCourse().getName());
temp.append(
"']"
);
if
(i!=courseList.size()-
1
){
temp.append(
","
);
}
}
temp.append(
"]"
);
this
.setAjaxResult(temp.toString());
return
"ajaxcheck"
;
}
|
struts.xml配置
1
|
<
result
name
=
"ajaxcheck"
>/WEB-INF/template/entity/pub/ajaxcheck.jsp</
result
>
|
ajaxcheck.jsp内容
1
2
3
|
<%@ taglib prefix="s" uri="/WEB-INF/struts-tags.tld" %>
<% response.setHeader("expires", "0"); %>
<
s:if
test
=
'ajaxResult!=null'
><
s:property
value
=
"ajaxResult"
escape
=
"false"
/></
s:if
><
s:else
><
s:property
value
=
"#request.ajaxResult"
escape
=
"false"
/></
s:else
>
|
本文转自 wbb827 51CTO博客,原文链接:http://blog.51cto.com/wbb827/1202719