html
<div class="layui-form-item">
<div class="layui-inline">
<label class="layui-form-label fwb" style="margin-top:4px;">原因</label>
<div class="layui-input-inline" style="margin-top:7px;">
<select name="punishreasonone" lay-filter="reason" id="punishreasonone" >
<option value="">请选择</option>
</select>
</div>
</div>
<div class="layui-inline" id="punishreasontwodiv" >
<select name="punishreasontwo" lay-filter="reasontwo" id="punishreasontwo" >
<option value="" >请选择</option>
</select>
</div>
</div>
js根据获取的数据动态生成select 的option
layui.form.on('select(reason)', function(data){
debugger;
var url = CONTEXT_PATH+"/dictionary/dictionaryItemList";
var param = {
"dictCode":data.value
};
$("#punishreasontwo option").remove();
var data = $.getData(url,param);
var punishreason = $("#punishreasontwo");
if(data.length==0){
$("#punishreasontwodiv").attr("style","display: none;");
return;
}else{
$("#punishreasontwodiv").attr("style","display: ;");
}
punishreason.append("<option value=''>请选择</option>");
$(data).each(function(index,obj){
punishreason.append("<option value='"+obj.itemCode+"'>"+obj.itemName+"</option>");
});
layui.form.render('select');
});
var params = {
"rewardpubId":$.QueryString("entityId")
};
var data = $.getData(CONTEXT_PATH + '/publish/get1',params);
if(data && data.status == WebConst.SUCCESS && data.data){
var reason = data.data.punishreasonone;
var url = CONTEXT_PATH+"/dictionary/dictionaryItemList";
var param = {
"dictCode":reason
};
var data = $.getData(url,param);
var punishreason = $("#punishreasontwo");
$("#punishreasontwo option").remove();
punishreason.append("<option value=''>请选择</option>");
$(data).each(function(index,obj){
punishreason.append("<option value='"+obj.itemCode+"'>"+obj.itemName+"</option>");
});
layui.form.render('select');
}
后台返回实体类封装返回的数据
private String rewardName;
private String punishreasonone;
private String punishreasontwo;
public String getPunishreasonone() {
return punishreasonone;
}
public void setPunishreasonone(String punishreasonone) {
this.punishreasonone = punishreasonone;
}
public String getPunishreasontwo() {
return punishreasontwo;
}
public void setPunishreasontwo(String punishreasontwo) {
this.punishreasontwo = punishrea
/**
* 设置原因
* @param rewardName
*/
public void setRewardName(String rewardName) {
if(StringUtil.isNotEmpty(rewardName) && rewardName.split(",").length == 1) {
punishreasonone = rewardName.split(",")[0];
}
if(StringUtil.isNotEmpty(rewardName) && rewardName.split(",").length == 2) {
punishreasonone = rewardName.split(",")[0];
punishreasontwo = rewardName.split(",")[1];
}
this.rewardName = rewardName;
}
public String getRewardNames() {
rewardNames="";
if(StringUtil.isEmpty(punishreasontwo)) {
String dictName=DictContext.getInstance().getDict("punishreason", punishreasonone);
if(!StringUtil.isEmpty(dictName)) {
rewardNames=dictName;
}
}
if(StringUtil.isNotEmpty(punishreasontwo)) {
String dictName=DictContext.getInstance().getDict(punishreasonone, punishreasontwo);
if(!StringUtil.isEmpty(dictName)) {
rewardNames=dictName;
}
}
return rewardNames;
}