当前位置: 移动技术网 > IT编程>开发语言>JavaScript > select2 插件编辑时设置默认值

select2 插件编辑时设置默认值

2018年03月01日  | 移动技术网IT编程  | 我要评论
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 + "'>&nbsp;" + item.name + "</option>");
            });
            /*设置默认值*/
            $(customerId).val(values);
        } else {
            // hint(rsp.message);
            console.log(rsp);
        }
    })
}
//使用
var customer = $("#customerId");
var val = data.customerId;
htDate(customer, val);

 

如对本文有疑问, 点击进行留言回复!!

相关文章:

验证码:
移动技术网