jquery multiselect reload

前端 未结 12 1983
轮回少年
轮回少年 2021-02-05 16:35

How can I add or remove options in JQuery UI Multiselect ? I am initializing the multiselect on page load and I need to remove existing values and add new values based on anothe

相关标签:
12条回答
  • 2021-02-05 17:12
    var valArr = ["1", "2"],
             i = 0,
          size = valArr.length,
      $options = $('#MySelect option');
    
    for (i; i < size; i++) {
      $options.filter('[value="' + valArr[i] + '"]').prop('selected', true);
    }
    
    $('#MySelect').multiselect('reload');
    

    1.valArr is values of select Options
    2.for loop to set selected to matched option based on valArr
    3.our changes is only in hidden select element
    4.to change in multiselect generated elements we need to reload
    5.every pluggin may have different name to reload eg:update,refresh

    0 讨论(0)
  • 2021-02-05 17:15

    I was trying to rebuild multiselect by .multiselect("destroy") and .multiselect(), but it wasnt working, so finally I find this solution worked for me.

    $.each(jsonArray, function(i, val) {
        $('#frmarticles-f_category_id').append('<option value="'+i+'">'+val+'</option>').multiselect('rebuild');
    });
    
    0 讨论(0)
  • 2021-02-05 17:17

    I used it in this way :

    $("#<%= cmbInBayiID.ClientID %>").multiselect().trigger('reset');
    

    It worked.

    0 讨论(0)
  • 2021-02-05 17:18
        function setMultiSelect(idElement, paramVal){
            eval("$('#"+idElement+"').multiselect('uncheckAll')");
            $.each($('input[name="multiselect_'+idElement+'"]'), function(k,i) {    
                if(paramVal.indexOf(this.value)!=-1){
                    this.checked = true; 
                }
            }); 
             eval("$('#"+idElement+"').multiselect('update')");
        }   
    
    0 讨论(0)
  • 2021-02-05 17:22

    For that one you could just destroy and reinitialize after changing...

    $("#multipleselectboxId").append(toAppend).multiselect("destroy").multiselect();
    

    There's also another plugin with a refresh function: EricHynds's Multiselect

    $("#multipleselectboxId").append(toAppend).multiselect("refresh");
    
    0 讨论(0)
  • 2021-02-05 17:24

    For wenzhixin MultiSelect:

    var i = jQuery('input');
    i.data('multipleSelect').$parent.remove();
    i.removeData('multipleSelect');
    i.show();
    
    0 讨论(0)
提交回复
热议问题