select2 插件编辑时设置默认值
程序员文章站
2022-04-14 13:00:10
function htDate(selectCustomerId, val) { var customerId = selectCustomerId; var values = val; ajaxJson('GET', webroot + "/customer/getOptionList", '',... ......
function htDate(selectCustomerId, val) { var customerId = selectCustomerId; var values = val; ajaxJson('GET', webroot + "/customer/getOptionList", '', function(err, rsp) { if (rsp.code == 200) { var text = rsp.result; customerId.select2({ placeholder: "请选择客户", allowClear: true, language: "zh-CN", width: '410px' // data:text, }); //绑定Ajax的内容 customerId.empty(); //清空下拉框 $.each(text, function(i, item) { customerId.append("<option value='" + item.id + "'> " + item.name + "</option>"); }); /*设置默认值*/ $(customerId).val(values); } else { // hint(rsp.message); console.log(rsp); } }) } //使用 var customer = $("#customerId"); var val = data.customerId; htDate(customer, val);
上一篇: canvas绘制随机验证码