问题
Is there a way to dynamically add grouping in multi select using this formation
var data = [
{label: "ACNP", value: "ACNP"},
{label: "test", value: "test"}
];
$("#multiselect").multiselect("dataprovider", data);
回答1:
Yes, you can now add groups with dataprovider
thanks to this pull request
See the documentation on .multiselect('dataprovider', data).
Demo in jsFiddle
You can compose like this:
var data = [{
title: 'First group',
children: [{ label: 'Cheese', value: 'cheese' },
{ label: 'Tomatoes', value: 'tomatoes' }]
}, {
title: 'Second group',
children: [{ label: 'Mozzarella', value: 'mozzarella' },
{ label: 'Mushrooms', value: 'mushrooms' }]
}];
$('.multiselect').multiselect('dataprovider', data);
<select class="multiselect" multiple="multiple"></select>
回答2:
@KyleMit for me instead of title, label works..
var data = [{
label: 'First group',
children: [{ label: 'Cheese', value: 'cheese' },
{ label: 'Tomatoes', value: 'tomatoes' }]
}, {
label: 'Second group',
children: [{ label: 'Mozzarella', value: 'mozzarella' },
{ label: 'Mushrooms', value: 'mushrooms' }]
}];
$('.multiselect').multiselect('dataprovider', data);
来源:https://stackoverflow.com/questions/24980692/bootstrap-multi-select-grouping-dynamicaly-using-array