Bootstrap multi select grouping dynamicaly using array

ε祈祈猫儿з 提交于 2019-12-23 01:52:24

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!