简体   繁体   English

Ajax调用后multiselect无法正常工作

[英]multiselect is not working after ajax call

I have a situation where i have to use multiselect for selecting a number of values from a dropdown,That dropdown is a dependend drop down ie on top of the drop down there is another dropdown which is supplying a list of values,when we click on that dropdown and select some value then on the basis of that value the below dropdown will generate.Now the problem is that the multiselect is comeing for the first time,but when i selecting the values from the 1st dropdown then the time creation of the second dropdown the multiselect is not working.I am giving my code here , 我有一种情况,我必须使用多重选择从下拉列表中选择多个值,该下拉列表是一个依赖项下拉列表,即在下拉列表的顶部,还有一个下拉列表在单击时提供了一个值列表该下拉列表并选择某个值,然后根据该值生成下面的下拉列表。现在的问题是多重选择第一次出现,但是当我从第一个下拉列表中选择值时,第二个创建时间下拉选择不起作用。我在这里给出我的代码,

//responsible for multiselet
$("#candyListIntAva").multiselect({
    disableIfEmpty: true,
});


//The first dropdown
$('#JobList').change(function (){

    //alert($('#JobList').val());

    var url = "<%=fetchCandidateByIdURL%>";
    var type = "fetchCandidate";
    var jobId = $('#JobList').val();

     jQuery.getJSON(url+"&jobId="+jobId+"&type="+type, function(data) { 

      //Inside this funtion the result is coming  i am appending the data to a div    
        $("#loadCandidate").html(data.searchResultArray);
   });

}); 

This is the HTML section 这是HTML部分

<table align="center">
<tr>
  <td class="interviewParams">Select Job ID</td>

<td class="interviewfields">
<select id="JobList" name="JobList">
        <option value="None">- Select Job ID -</option>
        <%
            while (rs.next()) {
                String jobid = rs.getString("jobOrderID");
        %>
        <option value="<%=jobid%>"><%=jobid%></option>
        <%
            }
        %>
    </select>

  </td>
 </tr>
 <tr>
<td class="interviewParams">Select Candidate</td>
<td class="interviewfields">
<div id="loadCandidate">
                 <select id="candyListIntAva" name="candyListIntAva" multiple="multiple">
                       <option value="None">--Select Candidate--</option>
                 </select>
          </div>

and this is the code by which i am taking out the data from server side 这是我从服务器端取出数据的代码

            rsServeResource = st.executeQuery(SQL);
            String generateOption = "";
            generateOption="<select id=\"candyListIntAva\" name=\"candyListIntAva\">";  
            generateOption+="<option value='None'>--Select Candidate--</option>";

            while (rsServeResource.next()) {  
                generateOption+="<option value=\'"+rsServeResource.getString(2)+"\'>"+rsServeResource.getString(1)+"</option>";  
           }  
           generateOption+="</select>";

           searchResultArray.put(generateOption);   
        jsonFeed.put("searchResultArray", searchResultArray);
        resourceResponse.setContentType("application/json");
        resourceResponse.setCharacterEncoding("UTF-8");
        resourceResponse.getWriter().write(jsonFeed.toString());

Now the problem is that i am applying the multiselect function to the candyListIntAva,but the callback is taking the data i am appending it a loadCandidate div.But if we apply candyListIntAva in both places then the second list will not be populated.But i also have to append the data to the div also.Can anyone tell me what is the solution?? 现在的问题是我正在对candyListIntAva应用multiselect函数,但是回调函数正在获取数据,因此我将其附加了一个loadCandidate div。但是如果我们在两个地方都应用candyListIntAva,那么第二个列表将不会被填充。还必须将数据附加到div。任何人都可以告诉我解决方案是什么?

use like below its working fine for me. 如下使用对我的工作罚款。

$('#csv_head').html('<select id="optgroup" class="ms" multiple="multiple" >'+data.header_arr+'</select>');

$('#csv_head').multiSelect({ selectableOptgroup: true });

Note:- 1. where csv_head is your div id and data.header_arr is your option string received from ajax call. 注意:1. 1.其中csv_head是您的div ID,data.header_arr是您从ajax调用接收的选项字符串。

  1. option string should be like below 选项字符串应如下所示

在此处输入图片说明

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM