下拉框清空与追加

清空:

$("#id").empty();

追加:

$("#tariffCode").append("<option value='" + tariffObj[i].code + "'>" + tariffObj[i].name + "</option>");

 

利用$ajax 动态 append("<option></option>") 会用到,每次追加前必须先清空。 

 

补充:

初始化加载下拉框:

前台接收

var tarifflist = '${tarifflist}';
var tariffObj = $.parseJSON(tarifflist);
if (tariffObj) {
   for (var i = 0; i < tariffObj.length; i++) {
       $("#tariffCode").append("<option value='" + tariffObj[i].code + "'>" + tariffObj[i].name + "</option>");
   }
}

后台拼装

Controller层

@RequestMapping(params = "accountOpening")
    public ModelAndView accountOpening(HttpServletRequest request) {
        ModelAndView modelAndView = new ModelAndView("ppms/customerManagement/account_opening");
        Date date = new Date();
        String spresetCredit = CustInfoManConstants.ACCOUNT_OPENING_TYPEGROUPCODE.PRESET_CREDIT.getTypeName();
        String semergencyCredit = CustInfoManConstants.ACCOUNT_OPENING_TYPEGROUPCODE.EMER_CREDIT_LIMIT.getTypeName();
        String slowCreditAlarm = CustInfoManConstants.ACCOUNT_OPENING_TYPEGROUPCODE.LOW_CREDIT_ALARM.getTypeName();
        String sarrearPercent = CustInfoManConstants.ACCOUNT_OPENING_TYPEGROUPCODE.DEFAULT_ARREAR_PCT.getTypeName();
        String presetCredit = dayendReconServiceI.getTypeCodeByGroupId(dayendReconServiceI.getGroupIdByGroupCode(spresetCredit));
        String emergencyCredit = dayendReconServiceI.getTypeCodeByGroupId(dayendReconServiceI.getGroupIdByGroupCode(semergencyCredit));
        String lowCreditAlarm = dayendReconServiceI.getTypeCodeByGroupId(dayendReconServiceI.getGroupIdByGroupCode(slowCreditAlarm));
        String arrearPct = dayendReconServiceI.getTypeCodeByGroupId(dayendReconServiceI.getGroupIdByGroupCode(sarrearPercent));

        modelAndView.addObject("presetCredit",presetCredit);
        modelAndView.addObject("emergencyCredit",emergencyCredit);
        modelAndView.addObject("lowCreditAlarm",lowCreditAlarm);
        modelAndView.addObject("arrearPct",arrearPct);

        //gst
        List list = customerInfoService.getGstCodeAndValue(date);
        String gstList = JSONObject.toJSONString(list);
        modelAndView.addObject("gstList",gstList);

        //tariff,应从数据库中查询可用tariffCode,根据code查询字典表中的name,存入list返回到前台
        List tarifCodeList = customerInfoService.getTarifCode(date);
        List generateTariffList = customerInfoService.generateTariffList(tarifCodeList);
        String tarifflist = JSONObject.toJSONString(generateTariffList);
        modelAndView.addObject("tarifflist",tarifflist);

        return modelAndView;
    }

Service层

@Override
    @DataSourceValue(DataSourceType.dataSource_jeecg)
    public List generateTariffList(List list) {
        List<Map<String, Object>> tariffList = new ArrayList();
        //查询字典表,根据groupId查询code和name的列表,遍历该列表,根据传入的tariffcode查name
        List<Map<String, Object>> mapList = tstypeService.getTypeCodeAndNameByGroupId(tstypeService.getGroupIdByGroupCode("TARIFF"));
        if (list != null && list.size() > 0) {
            for (int i = 0; i < list.size(); i++) {
                Map<String, Object> map = new HashMap();
                String tariffCode = list.get(i).toString();
                if (mapList != null && mapList.size() > 0) {
                    for (int j = 0; j < mapList.size(); j++) {
                        Map<String, Object> stringObjectMap = mapList.get(j);
                        String code = stringObjectMap.get("code").toString();
                        if (code.equals(tariffCode)) {
                            String tariffName = stringObjectMap.get("name").toString();
                            map.put("code", code);//tariffCode
                            map.put("name", tariffName);//tariffName
                            tariffList.add(map);
                        }
                    }
                }

            }
        }
        return tariffList;
    }

 

posted @ 2018-12-19 16:17  习惯沉淀  阅读(1655)  评论(0编辑  收藏  举报