2

부트 스트랩에이 플러그인을 사용 중입니다. 및이 예제 https://jsfiddle.net/hh2zrt82/ 선택한 값을 가져 오려고하지만 선택할 수 없습니다. 어떻게 값을 가져올 수 있습니까? 도움을 청합니다. jQuery로bootstrap dualistbox 값을 선택하는 방법

var data = [ 
     { 
      "id": 56, 
      "countryList_id": 10, 
      "port_iso": "India-pok" 
     }, 
     { 
      "id": 57, 
      "countryList_id": 10, 
      "port_iso": "India-nmp" 
     }, 
     { 
      "id": 58, 
      "countryList_id": 10, 
      "port_iso": "India-cop" 
     }, 
     { 
      "id": 61, 
      "countryList_id": 2, 
      "port_iso": "Bangladesh-dhp" 
     }, 
     { 
      "id": 62, 
      "countryList_id": 2, 
      "port_iso": "Bangladesh-brp" 
     }, 
     { 
      "id": 63, 
      "countryList_id": 3, 
      "port_iso": "Singapore-pos" 
     }, 
     { 
      "id": 64, 
      "countryList_id": 3, 
      "port_iso": "Singapore-SIN" 
     }, 
     { 
      "id": 65, 
      "countryList_id": 3, 
      "port_iso": "Singapore-zxczx" 
     }, 
     { 
      "id": 66, 
      "countryList_id": 2, 
      "port_iso": "Bangladesh-qewrqwe" 
     }, 
     { 
      "id": 67, 
      "countryList_id": 3, 
      "port_iso": "Singapore-erer" 
     }, 
     { 
      "id": 68, 
      "countryList_id": 3, 
      "port_iso": "Singapore-SIN" 
     } 
    ]; 
    var port_ids = [65,66,67]; 
    var options = ''; 

       for (var i = 0; i < data.length; i++) { 
        var a = 1; 
        for (var j = 0; j < port_ids.length; j++) { 
         // Appending "selected" attribute to the values which are already selected 
         if (port_ids[j] == data[i]["id"]) { 
          options += '<option value="' + data[i]["id"] + '" selected="selected">' + data[i]["port_iso"] + '</option>'; 
          a = 0; 
         } 
        } 
        if (a == 1) { 
         options += '<option value="' + data[i]["id"] + '">' + data[i]["port_iso"] + '</option>'; 
        } 
       } 


       $("select#country-of-operation-edit").empty().append(options); 

       $("#country-of-operation-edit").DualListBox(); 

답변

0

이 같은 것을 할 수있는 :

$('option.className[selected="selected"]')

을 : 당신은 당신에게 당신이 할 것이 경우 옵션 클래스를 추가 할 수 있습니다

$('option[selected="selected"]')

그러면 선택한 모든 옵션의 배열이 표시됩니다. 당신이 이름 속성 설정해야합니다 전에 위해

0

는 값을 선택하세요 :

$('[name="country-of-operation-edit[]"]').val() 
:

<select class="form-control" name="country-of-operation-edit[]" multiple="multiple" data-json="false" id="country-of-operation-edit"> 

을 그렇게 값을 얻을 수 있습니다 후

관련 문제