JEECG 框架下的 t:select 下拉框控件,只能是定义数据字典或者数据库中字段,如果在此控件中 ,下拉框的内容不能满足,我们该怎么办?
如下图 合同号的下拉框:
前端部分:
<input id="cpNo" name="cpNo" type="hidden" value='${opmJobPage.cpNo}' />
<select id="contractNo" name="contractNo" style=" border-radius: 3px; width: 100%; height:26px;border: 1px solid #ddd;color: #676a6c;" onchange="setCpNo()">
<option></option>
</select>
此处保留一个hidden的原先JEECG框架自动生成的Input框,然后加上一个自定义的select下拉框,PS:此处不要加值,加值的部分,需要放在后面的JS代码。
JS部分:
/*根据客户,货代模式获取合同号 */
function getCpNo(){
var customer=$("#customer").val();
var jobTypeSel = document.getElementById("jobTypeSel").value;
if(customer!=null&&jobTypeSel!=null){
$.ajax({
url : 'opmJobController.do?getContractNo',
type : 'post',
data : {"customer":customer,"jobTypeSel":jobTypeSel},
cache : false,
async : false,
dataType : "json",
success : function(data) {
if (data.success) {
$("#contractNo").empty().append("<option>Select</option>");
if(data.obj){
var contractNo =$("#cpNo").val();
var cpNoList =data.obj;
for(var i = 0; i < cpNoList.length; i++){
var code = cpNoList[i].SERIAL_NO;
if(contractNo==code){
$("#contractNo").append("<option value='"+code+"' selected='selected'>"+code+"</option>");
}else{
$("#contractNo").append("<option value='"+code+"'>"+code+"</option>");
}
}
}
}
}
});
}
}
function setCpNo(){
var cpNo = document.getElementById("contractNo").value;
$("#cpNo").val(cpNo);
}
后端部分:
@RequestMapping(params = "getContractNo")
@ResponseBody
public AjaxJson getCpNo(String customer ,String jobTypeSel, HttpServletRequest request) {
AjaxJson j = new AjaxJson();
String message = null;
String contract= null;
try {
if(jobTypeSel.equals("FWNG")||jobTypeSel.equals("FWG")){
contract = "1";
}else{
contract = "2";
}
String hql = "select SERIAL_NO from cbm_voy_charter where CHARTERER_NAME=? and CONTRACT=?";
List<Map<String, Object>> coaList = systemService.findForJdbc(hql,customer,contract);
if (coaList != null && coaList.size() > 0) {
j.setObj(coaList);
}
}catch (Exception e) {
e.printStackTrace();
throw new BusinessException(e.getMessage());
}
j.setMsg(message);
return j;
}