select2 插件编辑时设置默认值
程序员文章站
2022-07-02 17:47:28
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);
上一篇: 前端综合学习笔记---变量类型、原型链、作用域和闭包
下一篇: MyCAT学习总结