花了我快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();