ICode9

精准搜索请尝试: 精确搜索
首页 > 其他分享> 文章详细

layui下拉框

2021-04-13 10:35:05  阅读:18  来源: 互联网

标签:layer layui json res var data 下拉框


花了我快8个小时结合了所有例子才得到的可用代码

   <div class="layui-form-item" >
                <label class="layui-form-label">所属脑电中心</label>
                <div class="layui-input-block">
                <select name="centerid" id="centerid" lay-filter="centerid" >
                    <option value="">请选择</option>
                </select>
                </div>
            </div>
    layui.use( ['element', 'form','layer','layedit'], function (){
                        //只有执行了这一步,部分表单元素才会自动修饰成功
                        var form = layui.form,
                         element = layui.element;
                    $ = layui.jquery;
                    var layer = layui.layer;
                    var layedit = layui.layedit;
                        $.ajax({
                            type: "get",
                            dataType: 'json',
                            url: 'user?method=getBrainCenter',
                            success: function (res) {
                                console.log(res)
                                if (res.data) {
                                    alert("11111")
                                        var optionHtml = '';
                                        for(var i in res.data){
                                            alert("这个值是:"+i)
                                            var value1 = res.data[i]['id'];
                                            console.log(value1)
                                            var value2 = res.data[i]['name'];
                                            console.log(value2)
                                            optionHtml += "<option value='" + value1 + "'>" + value2 + "</option>";
                                        }
                                    $('#centerid').append(optionHtml);

                                    //重新渲染
                                    layui.form.render("select");
                                } else {
                                    layer.msg(res.message);
                                }
                            }
                        })
                    });

    case"getBrainCenter":
                List<Organization> organizations=userService.getAllOrganiztion("center");
                JSONObject json = new JSONObject();
                json.put("msg", "上传成功");
                json.put("code", 0);
                json.put("data", organizations );
                PrintWriter out = resp.getWriter();
                out.println(json);
                out.flush();
                out.close();

标签:layer,layui,json,res,var,data,下拉框
来源: https://www.cnblogs.com/hanabi-521/p/14652013.html

专注分享技术,共同学习,共同进步。侵权联系[admin#icode9.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有