layui 下拉框 多选 及回显

   <div class="layui-form-item layui-col-md4">
                        <label class="layui-form-label"><span class="layui-form-required">*</span>主营类目</label>
              <div class="layui-input-block">
                <select name="resourceType"  id="resourceType" lay-filter="resourceType"  xm-select="xxx">
              
                 </select>
               </div>
      
   </div>

插件下载
layui 下拉框 多选 及回显_第1张图片

<%--需引入js 以及css--%>
<script src="<%=request.getContextPath()%>/resources/xyjj-web/assets/js/jquery-1.9.1.min.js"></script>
<script src="<%=request.getContextPath()%>/resources/xyjj-web/assets/plugins/layui/layui.js"></script>
<link href="<%=request.getContextPath()%>/resources/plugin/layui/css/formSelects-v4.css" rel="stylesheet" />
<script src="<%=request.getContextPath()%>/resources/plugin/layui/formSelects-v4.js" charset="utf-8"></script>
<script>

    var basePath= "<%=request.getContextPath()%>" ;
    layui.use(['form', 'upload'], function () {
     
        var form = layui.form, $ = layui.jquery,
            upload = layui.upload;

        var formSelects = layui.formSelects;
        form.render();

        layer.ready(function(){
     

            var keys = [];

            $.ajax({
     
                url :  basePath + "/agriVendor/getCodeAgri",
                type:'POST',//默认以get提交,以get提交如果是中文后台会出现乱码
                dataType : 'json',
                async: false,
                success : function(data) {
     
                    for(var i=0;i<data.length;i++){
     
                        //因为formslects,规定了数据格式
                        var temp = {
     "name":data[i].name,value:data[i].code};
                        keys.push(temp);
                    }
                }
            })
            console.log(keys);

            //local模式 本地数据
            formSelects.data('xxx', 'local', {
     
                arr: keys
            });

        });
<%--需引入js 以及css--%>
<link href="<%=request.getContextPath()%>/resources/plugin/layui/css/formSelects-v4.css" rel="stylesheet" />
<script src="<%=request.getContextPath()%>/resources/plugin/layui/formSelects-v4.js" charset="utf-8"></script>
<script>
    var basePath= "<%=request.getContextPath()%>" ;

    layui.use(['form', 'upload'], function () {
     
        var form = layui.form, $ = layui.jquery,
            upload = layui.upload;
        var formSelects = layui.formSelects;
        <%-- 获取 字段 这里是以 , 拼接的--%>
        var diclistsheshi = "${vendor.resourceType}";
    
        layer.ready(function(){
     
            var keys = [];

            $.ajax({
     
                url :  basePath + "/agriVendor/getCodeAgri",
                type:'POST',//默认以get提交,以get提交如果是中文后台会出现乱码
                dataType : 'json',
                async: false,
                success : function(data) {
     
                    for(var i=0;i<data.length;i++){
     
                        //因为formslects,规定了数据格式
                        var temp = {
     "name":data[i].name,value:data[i].code};
                        keys.push(temp);
                    }
                }
            })
            //local模式 本地数据
            formSelects.data('xxx', 'local', {
     
                arr: keys
            });
            
            if(diclistsheshi != "" && diclistsheshi != null ){
     
             
                var lisarr = diclistsheshi.split(",");
                formSelects.value('xxx',lisarr,true);
            }
             selectfile();
        });

最后呈现
layui 下拉框 多选 及回显_第2张图片

你可能感兴趣的:(layui 下拉框 多选 及回显)