wumi_blog
wumi_blog copied to clipboard
jq select插件 select2踩坑
$('#myselect').select2({
data:dataArr,// 数据生成option
placeholder:'请选择数据项',
multiple:true,// 多选
closeOnSelect: false,// 选完是否收起
dropdownParent: $('.history-data-select-div') // dropdown位置相关 多选可能会有问题,会把框挡住
});
碰到了个 主要是清空option的问题
api提供了个
The destroy method will remove the Select2 widget from the target element. It will revert back to a standard select control:
$('#mySelect2').select2('destroy');
但用起来好像并没有销毁组件,只是变成了原select;
查清除数据的api网友们提供了$('#mySelect2').select2('data', null);
,$("#mySelect2").select2("val", "");
等,由于种种原因也并没有生效
api提供的
You may clear all current selections in a Select2 control by setting the value of the control to null: $('#mySelect2').val(null).trigger('change');
不知怎么也没生效,估计是我操作问题.
结果我是在每次调用$('#myselect').select2({data:dataArr})
动态生成option前,把真实的select的option清空,通过:$('#myselect').html('')