Bootstrap Select Multi-select drop-down box assignment value
Success:function (data) { var oldnumber = new Array (); $.each (data, function (i) { oldnumber.push (data[i].id); }); $ (' #editcolor. Selectpicker '). Selectpicker (' Val ', oldnumber);//select $ (' #editcolor. Selectpicker ') by default. Selectpicker (' Refresh ');}
Above is Ajax get the default value, remember Selectpicker is through the ID to operate,
<div class= "col-md-8" id= "Editcolor" > <select placeholder= "Please select Color" id= "selectpickerallstr" name= " Selectpickerallstr " class=" Selectpicker show-tick form-control "data-style=" btn-success "multiple Data-live-search= "true" > </select></div>
You can refer to an article in front of me, I'll post it again get the code
Select color var loadtemplatecolor = function () { $.ajax ({ type: ' GET ', url:root + '/mycolor ', success: function (data) { var data = eval (data); $.each (data, function (i) { $ ("<option value=" "+ data[i].id +" ' > "+ data[i].text +" </option> ") . App EndTo (". Selectpicker"); }); $ ('. Selectpicker '). Selectpicker ({ //I am a one-time assignment for all selectpicker operations, if you want to assign a value individually, OK, then assign the value: //appendto ("# Editcolor. Selectpicker "), in this case, on your select element cover a div, //with the DIV ID to mark the selectpicker you want to manipulate, that is, you want to manipulate the SELECT element tag style: ' Btn-info ', size:8 })}} );
Fix a value at a time:
$ (' #editcolor. Selectpicker '). Selectpicker (' Val ', 1);//Selected by default
$ (' #editcolor. Selectpicker '). Selectpicker (' refresh ');
A lot of values are assigned at once:
Success:function (data) { var oldnumber = new Array (); $.each (data, function (i) { oldnumber.push (data[i].id); }); $ (' #editcolor. Selectpicker '). Selectpicker (' Val ', oldnumber);//select $ (' #editcolor. Selectpicker ') by default. Selectpicker (' Refresh ');}
Dynamically assigned values
<select id= "filetype" name= "filetype" class= "Selectpicker show-tick dropup" data-live-search= "true" onchange= " Filetypechange (); " ></select>
Initialize call Getdata4select ("filetype", "file_type");
/**
* Query the dictionary data according to the dictionary type for bootstrap select to use
* @param ID
* @param dicttype
*/
function Getdata4select (id,dicttype) {
var url = '/yh/com/dominsoft/act/yhtypehandleact/getitemtype.act?type= ' +dicttype;
var json = Getjsonrs (URL);
if (json.rtstate = = "0") {
var rtdata = Json.rtdata;
var typedata = Rtdata.typedata;
JQuery (' # ' +id). Append ("<option value=" > Please select </option> ");
for (var i = 0; i < typedata.length; i++) {
JQuery (' # ' +id). Append ("<option value=" + Typedata[i].typeid + ">" + Typedata[i].typedesc + "</option>");
}
}
JQuery (' # ' +id). Selectpicker ();
}
Selectpicker Lado box Ajax Async or Advance assignment = "Default value