2

Ich verwende dieses Plugin für Bootstrap 3 https://github.com/Geodan/DualListBox, und dieses Beispiel https://jsfiddle.net/hh2zrt82/ Ich versuche, eine ausgewählte Werte zu bekommen, aber ich kann nicht, wie kann ich einen ausgewählten Werte zu bekommen. Verwerten Sie Ihre Hilfe.Bootstrap Dualistbox wie Werte erhalten

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(); 

Antwort

0

Mit jQuery Sie so etwas tun könnte:

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

Sie könnten eine Klasse Sie Optionen, in denen hinzufügen möchten Fall, dass Sie tun würde:

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

Dadurch erhalten Sie ein Array aller ausgewählten Optionen.

0

Um ausgewählte Werte zu erhalten, bevor Sie name-Attribut gesetzt haben:

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

nach können Sie die Werte erhalten so:

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