问题
Hi guys I am trying to use select2 with one disabled value.
I am trying to implement it like
$('#select_currency').select2('data', preloaded_data);
I have been reading about Lock selections but I am not able to implement it, could you please someone let me know how to implement it or is there any tutorial about it. Thank you.
回答1:
You can easely add locked="locked"
if you use v3.5 http://select2.github.io/select2/#locked-selections.
But in v.4.x this functionality is removed.
I've found solution (or hack:) ) for v.4.x, a little bit dirty with error in console, but it works. Anyway it is best solution what I've found. Check my jsfiddle:
https://jsfiddle.net/o3s3y42e/4/
回答2:
And in a select dropdown you can just add the locked="locked"
attribute.
<select id="sharewith" multiple="true">
<option value="self" selected="selected" locked="locked">myself</option>
</select>
回答3:
It's simple, just pass all items you want to lock, e.g
$('#select_currency').select2('data', [{id:'myr', text:'Malaysia Ringgit', locked:true}]);
来源:https://stackoverflow.com/questions/16564425/how-to-implement-select2-with-lock-selection