创建子组的下拉列表


Dropdownchecklist creating subgroups

>我有使用下拉列表的列表,我想从列表的元素创建子组。因此,如果我单击子组复选框,它将检查绑定到它的所有元素。

我的PHP生成的HTML代码:

<select name="data[EcnRequests][groups][]" id="groupSelection" multiple="" style="display:   none;">
<option id="group_0" style="background-color: #eee;">All</option>
<option name="groupBy" id="group_A" style="background-color: #eee;"> A_ALL </option>
<option name="groupBy" id="group_B" style="background-color: #eee;"> B_ALL </option>
<option id="group_194">A_A</option>
<option id="group_195">A_B</option>
<option id="group_196">A_C</option>
<option id="group_197">A_D</option>
<option id="group_198">B_A</option>
<option id="group_199">B_B</option>
<option id="group_201">B_C</option>
<option id="group_202">C_A</option>
</select>

我的jQuery:我试过这个,但刷新不让选中复选框

    $j("#groupSelection").dropdownchecklist({firstItemChecksAll: true, emptyText: "Select groups", width: 180,  maxDropHeight: 200,
         onComplete: function(checkbox,selector) {
          $j('#EcnRequestsAdvancedSearchForm').submit();
        },
        onItemClick: function(checkbox, selector){
            var justChecked = checkbox.prop("checked");
            if(checkbox.val().match(/_ALL/g)!=null){

                if (justChecked){
                    arrayFromPHP[checkbox.val().split("_")[0]].forEach(function(e) {
                        console.log(selector.options[11].selected);
                        $j('#groupSelection > option[id=group_'+e+']').prop('selected', true);
                        $j('#groupSelection').dropdownchecklist("refresh");
                    });
                }
                else {
                    arrayFromPHP[checkbox.val().split("_")[0]].forEach(function(e) {
                        $j('#groupSelection > option[id=group_'+e+']').prop('selected', false);
                        $j('#groupSelection').dropdownchecklist("refresh");
                    });
                }
            }
        }

    });

My arrayFromPhp:

Object {A: Array[4], B: Array[3] }
A: Array[4]
0: 194
1: 195
2: 196
3: 197
length: 4
B: Array[3]
0: 199
1: 200
2: 201
length: 3

我找到了解决方案:

    $j("#groupSelection").dropdownchecklist({firstItemChecksAll: true, emptyText: "Select groups", width: 180,  maxDropHeight: 200,
    onComplete: function(checkbox,selector) {
          $j('#EcnRequestsAdvancedSearchForm').submit();
    },
    onItemClick: function(checkbox, selector){
        var justChecked = checkbox.prop("checked");
        if(checkbox.val().match(/_ALL/g)!=null){
            var id = checkbox.val().split("_")[0];
            if (justChecked){
                $j('#groupSelection > option[id=group_'+id+']').attr('selected', 'selected');
                arrayFromPHP[id].forEach(function(e) {
                    $j('#groupSelection > option[id=group_'+e+']').attr('selected', 'selected');
                });
            }
            else {
                $j('#groupSelection > option[id=group_'+id+']').removeAttr('selected');
                arrayFromPHP[checkbox.val().split("_")[0]].forEach(function(e) {
                    $j('#groupSelection > option[id=group_'+e+']').removeAttr('selected');
                });
            }
            $j('#groupSelection').dropdownchecklist("refresh");
        }
    }

});