这几天写的项目,发现在初始化select2之后无法使用data属性动态改变数据,如果使用以下的代码
var client_address = $("#client-address-select");
client_address.select2({
data:return_data.address
});
Chrome提示: Option ‘data’ is not allowed for Select2 when attached to a <select> element
解决方法如下:
var client_address = $("#client-address-select");
client_address.select2("destroy");
client_address.html("");
$.each(return_data.address,function(){
client_address.append('');
});