MaterializeCSS - 多个 Select - 取消选择后值保留在数组中

MaterializeCSS - Multiple Select - value stays in array after unselecting

当我在 MaterializeCSS 的多个 selection 中取消 select 值时,它仍然在值数组中,我找不到修复它的方法。如果我使用某些功能从原始 select 中取消 select 选项但 $('.dropdown-content li').click() 不做任何事情所以我不能只做类似的事情

$('.dropdown-content li.active').click(function() {
    //take index of this and unselect option with same index from <select>
});

(请忽略截图错误,无关)

我遇到了同样的问题并写了一个小的解决方法。 http://jsfiddle.net/9bL25jw9/2/

$(document).ready(function () {
    $('select').material_select();
    $('select').change(function(){
        var newValuesArr = [],
            select = $(this),
            ul = select.prev();
        ul.children('li').toArray().forEach(function (li, i) {
            if ($(li).hasClass('active')) {
                newValuesArr.push(select.children('option').toArray()[i].value);
            }
        });
        select.val(newValuesArr);
    });
});