I\'m using the bootstrap select plugin. I am populating a dynamically created select like so:
var select = $(\'\', {
\'class\':\"selectpi
You need to append the <select />
you create to the DOM before calling selectpicker()
on it, something like this:
var $select = $('<select/>', {
'class':"selectpicker"
});
for (var idx in data) {
$select.append('<option value=' + data[idx].id + '>' + data[idx].Text + '</option>');
}
$select.appendTo('#myElement').selectpicker('refresh');
Note the use of append()
, and also the removal of hasOwnProperty
- you're already looping through the properties of the object so that method call is redundant.