将变量传递给multiSelect值

时间:2018-03-20 06:39:00

标签: javascript jquery bootstrap-multiselect

$.ajax({
  type:'POST',
  data:({value:10}),
  url:'count.php',
  success:function(data){
   var data=jQuery.parseJSON(data);
   console.log(data);
   if(data.status==true){
      var table=data.data.row;
      var staffs=data.staff.STAFF;
      var users=staffs.join();
      var user = '\'' + users.split(',').join('\',\'') + '\'';
      $("#my_multi_select2").multiSelect('select', [user]);
      //$("#my_multi_select2").multiSelect('select',['3','4']);
     }
   }
 })

我的用户值为'3','4','5','6' 我如何将其作为变量传递给多选所选值 请帮帮我.....

2 个答案:

答案 0 :(得分:2)

您只需要将值作为数组传递给multiselect:



jQuery(document).ready(function($){
    var users = '3,4,5,6';
    var userarray = users.split(',');

    $("#my_multi_select2").val( userarray );

    console.log( userarray );
});

<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<select id="my_multi_select2" multiple>
    <option value="1">User 1</option>
    <option value="2">User 2</option>
    <option value="3">User 3</option>
    <option value="4">User 4</option>
    <option value="5">User 5</option>
    <option value="6">User 6</option>
    <option value="7">User 7</option>
    <option value="8">User 8</option>
</select>
&#13;
&#13;
&#13;

根据你的例子:

$.ajax({
    type: 'POST',
    data: ({value:10}),
    url: 'count.php',
    success: function(data){
        var data = jQuery.parseJSON(data);
        console.log(data);
        if( data.status == true ){
            var table   = data.data.row;
            var staffs  = data.staff.STAFF;  //staffs  = [["3"],["2"],["4"],["5"]]
            var users   = staffs.join();     //users   = "3,2,4,5"
            var userArr = users.split(',');  //userArr = ["3", "2", "4", "5"]
            $("#my_multi_select2").val(userArr);
        }
    }
});

答案 1 :(得分:0)

Xhynk回答得很好。但仍然分享我的尝试。

Sub GoAwayDumbText()
 Dim oPres As Presentation
 Dim oSlides As Slides
 Dim oSld As Slide
 Dim oShp As Shape
 Dim PathSep As String
 Dim sTempString As String

#If Mac Then
PathSep = ":"
#Else
PathSep = "\"
#End If

Set oPres = ActivePresentation
Set oSlides = oPres.Slides

For Each oSld In oSlides
For Each oShp In oSld.Shapes
    If oShp.Left <= 135 And oShp.Top >= 260 Then
    oShp.Delete
    Else
    End If
Next oShp

Next oSld

End Sub