级联查询

  getLines('${param.qlineId}','${param.qsectionId}');

getSections('${param.qlineId}','${param.qsectionId}');

 getWokPoints('${param.qsectionId}','${param.qworkPointId}');

<select id="qlineId" name="qlineId" onchange="getSections(this.value,'')"> ////select默认值的设置

方法1<option value=" " selected>666</option>

方法2<option value=" " selected=“selected”>666</option>

后台

public ActionForward getLines(ActionMapping mapping, ActionForm form,HttpServletRequest request, HttpServletResponse response){
Map map =initParamMap(request);
List<DtaqLine> sections=dataLiveVideoManager.getLines(map);
JSONArray jsArry=new JSONArray();
JSONObject jsObj=new JSONObject();
for(DtaqLine obj:sections){
jsObj=new JSONObject();
jsObj.put("id",obj.getLine_id().toString());
jsObj.put("name",obj.getLine_name());
jsArry.add(jsObj);
}
super.renderText(response, jsArry.toString());

return null;
}

1页面直接先调用方法

例如 getLines('${param.qlineId}','${param.qsectionId}');////js部分

<select id="qlineId" name="qlineId" onchange="getSections(this.value,'')"></select>

2,js方法的部分

//qlineId是当前选择的值 msg是后台传的字符串 type区分第几级的查询

第一级:function getLines(qlineId,qsectionId){
$.post("dataLiveVideoAction.do?method=getLines",function(msg){
fillJsonNoSelect($("#qlineId"),msg,qlineId,1,qsectionId);
});
}

第二级:function getSections(qlineId,qsectionId){
getWokPoints('','');
if(qlineId!=''){
$.post("dataLiveVideoAction.do?method=getSections&qlineId="+qlineId,function(msg){
fillJsonNoSelect($("#qsectionId"),msg,qsectionId,2);
});
}else{
fillJsonSelect($("#qsectionId"),"","");
}
}


第三级 function getWokPoints(qsectionId,qworkPointId){
getTypes('','');
if(qsectionId!=''){
$.post("dataLiveVideoAction.do?method=getWokPoints&qsectionId="+qsectionId,function(msg){
fillJsonNoSelect($("#qworkPointId"),msg,qworkPointId,3);
});
}else{
fillJsonSelect($("#qworkPointId"),"","");
}
}

//未做选择时赋予的请选择

function fillJsonSelect(obj,jSonStr,setOb){
var selectObj = initSelect(obj,true) ;
if(jSonStr != null && jSonStr != ""){
var jSobj = JSON.parse(jSonStr);
var count=jSobj.length;
for(var i=0; i<count; i++){  
var setStr="";
if(jSobj[i].id==$.trim(setOb)){
   setStr="selected";
}
selectObj.append("<option value='"+jSobj[i].id+"' "+setStr+">"+jSobj[i].name+"</option>") ;

}
}



function fillJsonNoSelect(obj,jSonStr,setOb,type,section){
var selectObj ;
if(jSonStr != null && jSonStr != ""){

var jSobj = JSON.parse(jSonStr);
var count=jSobj.length;
if(count==1){

selectObj = initSelect(obj,"false") ;//此方法是给定请选择
}else{

selectObj = initSelect(obj,true) ;
}
var seleteId='';
for(var i=0; i<count; i++){

var setStr="";
seleteId=jSobj[i].id;

if(jSobj[i].id==$.trim(setOb)){
   setStr="selected"; ////默认标识
}
selectObj.append("<option value='"+jSobj[i].id+"' "+setStr+">"+jSobj[i].name+"</option>") ;

if(count==1){
if(type==1){
getSections(seleteId,section);
}else if(type==2){
//getWokPoints(seleteId,'');
}
}
}
}


function initSelect(selectObj,showNull){
selectObj.find("option").remove();
selectObj.append("<option value=''>--请选择--</option>") ;
return selectObj ;
}




评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值