• 下拉框 显示name 隐藏code


    暂未做详细整理, 后期有机会完善

    jsp
        是否有效:
        <s:select id="queryIsValid" name="configBean.queryIsValid" data="${configBean.queryIsValid}"  cssClass="box_cangdan" list="#{'':''}"></s:select>
    
    
    js
        var isValidData = [{"value":"0","name":"否"},
        {"value":"1","name":"是"}];
    
        /**
         * 绑定是否有效
         */ 
        function bindIsValidData(idArray){
           $.each(idArray, function(i, n){ 
                 var oldValue = $("#"+n).attr("data");
                 $("#"+n).empty();
                 $("#"+n).append("<option value=''></option>");
                 for(var i in isValidData){
                     $("#"+n).append("<option value='"+isValidData[i].value+"'>"+isValidData[i].name+"</option>");
                 }
                 $("#"+n).val(oldValue);
           });
        }
    
        $(function(){
            bindIsValidData(["queryIsValid"]);
        });
    
    
    后台 - 具体的查询功能
        EntBusinessConfigBean.java    
            属性(setter/getter)private String queryIsValid = "";
    
        xxxAction
            属性(setter/getter)private EntBusinessConfigBean configBean = new EntBusinessConfigBean();      //接收参数bean
            map.put("queryIsValid", null==configBean?null:configBean.getQueryIsValid());
    
            showBeans = entBusinessConfigService.queryBusinessConfigDic(map, page);
    
            Object queryIsValid = map.get("queryIsValid");
            if (queryIsValid != null && queryIsValid.toString().trim().length() > 0) {
                sql.append(" and t.Is_Valid = ? ");
                params.add(queryIsValid);
            }
    
            //List<Map<String, Object>>
            return new SQLQueryAdapter(this.hibTemplate).executeNativeSqlResultMap(sql.toString(), params,page);

    Java后台返回Map(自动转Json),前端进行遍历处理

    返回数据格式如下

    {
        "result": true,
        "operModuleMap": [{
            "value": "舱单申报",
            "key": "AIRCDSB"
        }, {
            "value": "信息共享",
            "key": "AIRXXGX"
        }, {
            "value": "运输工具申报",
            "key": "AIRYSGJSB"
        }]
    }

    后端Struts部分代码

    //用于Ajax返回数据(setter/getter)
    private Map<String,Object> validateExists = new HashMap<String, Object>();
    
    @Action(value = "cheangeDomainCode",
            results = {
                       @Result(name = "success", type = "json", params= {"root","validateExists"})}
            )
    public String cheangeDomainCode(){
        try {
            String domainCode = SessionUtil.getRequest().getParameter("domainCode");
            Map<String, String> map = new HashMap<String, String>();
            map.put("domainCode", domainCode);
            operModuleMap = operationalGuidelinesConfigService.queryOperModuleByDomainCode(map);
            if (null != operModuleMap && operModuleMap.size() > 0) {
                validateExists.put("result", true);
                validateExists.put("operModuleMap", operModuleMap);
            } else {
                validateExists.put("result", false);
                validateExists.put("info", "没有找到符合条件的记录!");
            }
        } catch (Exception e) {
            log.error("[Action cheangeDomainCode Exception message]: "+e.getMessage(), e);
            e.printStackTrace();
            validateExists.put("result", false);
            validateExists.put("info", e.getMessage());
        }
        return SUCCESS;
    }

    前端使用全部变量接收

    //全局变量: 业务模块名称
    var operModuleArr = "";
    //查询业务模块名称, 用于下拉框数据填充满
    function findOperModuleMap(domainCode, moduleCode) {
        $.ajax({
            url:"cheangeDomainCode.action?domainCode="+domainCode,
            dataType : "json",
            async: false, //默认为true,改为false 则为同步请求
            cache: false,
            success:function(data){
                if (data.result) {
                    operModuleArr = data.operModuleMap;
                }
            }
        });
    }

    前端进行遍历追加到下拉选项

    $("#operModuleMap").empty();
    $("#operModuleMap").append("<option value=''>请选择</option>");
    for(var i=0; i < data.operModuleMap.length; i++){
        $("#operModuleMap").append("<option value="+data.operModuleMap[i].key+">"+data.operModuleMap[i].key + "/" +data.operModuleMap[i].value+"</option>");
        /*if(!isEmpty(moduleCode) && data.operModuleMap[i].key==moduleCode) {
            $("#operModuleMap").append("<option value="+data.operModuleMap[i].key+" selected>"+data.operModuleMap[i].key + "/" +data.operModuleMap[i].value+"</option>");
        }else {
            $("#operModuleMap").append("<option value="+data.operModuleMap[i].key+">"+data.operModuleMap[i].key + "/" +data.operModuleMap[i].value+"</option>");
        }*/
    }
  • 相关阅读:
    算法设计--求连续子向量的最大和问题--论想法思路的重要性
    --a和a--
    程序员一个知道的一些法则
    django admin
    Python递归
    Python内置函数
    Python协程函数
    Python 生成器
    Python迭代器
    Python装饰器
  • 原文地址:https://www.cnblogs.com/jkfeng/p/11867403.html
Copyright © 2020-2023  润新知