2017-11-17 9 views
0

を削除することはできません空のスパンを追加します。Selectセレクトは私がこのように定義された複数選択を持っている

<select class="form-control" name="citiesNotValid"> 

私はSELECT2としてそれを初期化する場合は、選択要素、1つの作業を複製し、私の予め選択されたでいっぱいオプションで、もう一方は空で動作しません。 これはSELECT2のinizializationです:

$(s).select2({ 
    language: "it", 
    placeholder: { 
     id: '-1', // the value of the option 
     text: 'All' 
    }, 
    width: '100%', 
    //multiple: true, 
    allowClear: true, 
    ajax: { 
     delay: 500, 
     type: "POST", 
     contentType: "application/json; charset=utf-8", 
     url: o, 
     dataType: "json", 
     cache: 1, 
     data: function (params) { 
      var query = JSON.stringify({ 
       country_code: country, 
       search: params.term 
      }) 

      return query; 
     }, 
     processResults: function (t) { 
      return { 
       results: $.map(JSON.parse(t.d), function (obj) { 
        if (obj.city_name == "-") { 
         return { id: "-1", text: "Tutte" }; 
        } 
        return { id: obj.city_name, text: obj.city_name }; 

       }) 
      }; 
     }, 
     error: function (t, o, i) { 
      var n = "Si è verificato un errore. Controlla di aver passato correttamente tutti i parametri."; 
      //if (t.statusText != null && t.statusText != "") 
      // n = t.statusText; 
      "toastr" == a && toastr ? toastr.error(n) : "notific8" == a && $.notific8 ? ($.notific8("zindex", 11500), $.notific8(n, { 
       theme: "ruby", 
       life: 3e3 
      })) : console.log(n) 
     } 
    }, 
    minimumInputLength: 2, 
}); 

}

私はこの方法でコードを実行すると、それは私が私のクロームコンソールでそれを見ることができ、第二<span>要素を作成しますが、私がしようとした場合それが存在しないように、私はそれを見つけることができません私のjQueryのコードで削除する。私が指摘し enter image description here

もう一つ enter image description hereは、私は私の選択select2クラスに追加した場合、それは1つだけ選択を作成しますが、Ajaxがトリガされないということです。

答えて

0

空のoptionをあなたの最初の要素として使用していますか?その場合は、削除してください。

+0

いいえ、最初は空のオプションがありません –

関連する問題