select2 multiselect - 选择一个组及其所有子组,但在未选择组时允许选择多个子组

时间:2014-06-20 16:30:33

标签: javascript jquery jquery-select2 multi-select

使用jQuery插件select2 multlectlect如何选择一个组及其所有子组件,但在未选择组时允许选择多个子组件?您将在下面找到一个允许选择组的jsfiddle,但一次只能选择一个子组。对此的任何帮助将不胜感激。

jsfiddle select2 multiple - http://jsfiddle.net/jcUUG/145/

HTML CODE:

<input type='hidden' id='select'>

JS CODE:

$(function () {

var select2_ary = [];

select2_ary.push(

{id: 'numbers', text: 'numbers',
    children: [
        {id: "numbers", text: "1"},
        {id: "numbers", text: "2"},
        {id: "numbers", text: "3"},
        {id: "numbers", text: "4"},
        {id: "numbers", text: "5"}
    ]
}, 
{id: 'letters', text: 'letters',
    children: [
        {id: "letters", text: "A"},
        {id: "letters", text: "B"},
        {id: "letters", text: "C"},
        {id: "letters", text: "D"},
        {id: "letters", text: "E"}
    ]
}
);

$("#select").select2({
    placeholder: "Select",
    data: select2_ary,
    multiple: true,
    width: "300px"
});
});

1 个答案:

答案 0 :(得分:0)

您不能拥有多个选项的相同ID,这就是您获得此行为的原因。

看看这个Select2 with multiple nested groups