Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

230
Vistas
How to bind data to bootstrap select

json data:

["string 1","string 2","test 07 ","here is test"]

and this is html

  <select class="selectpicker" id="ddl_location">
    <option select="selected">Select Location </option>
  </select>

and here is JQuery code

 for (var i = 0; i < jsonData.length; i++) {
     $("#ddl_location").append('<option value="' + jsonData[i] + '">' + jsonData[i] + '</option>');
      }

the issue is that

data is not populated in drop-down list

about 4 years ago · Santiago Trujillo
3 Respuestas
Responde la pregunta

0

after working around the issue, the solution was :

 var jsonData = JSON.stringify(data);
     $.each(JSON.parse(jsonData), function (idx, obj) {
        $("#ddl_location").append('<option value="' + obj.id + '">' + obj.location + '</option>').selectpicker('refresh');
     });

step 1: stringify received object
step 2: use each function instead of for loop
step 3: parse the data using JSON.parse(jsonData )
step 4: refresh drop-down list every time you append data to drop-down list using .selectpicker('refresh')

about 4 years ago · Santiago Trujillo Denunciar

0

remember to append $select.append(data).selectpicker('refresh'); when you don't get data populate in drop down

about 4 years ago · Santiago Trujillo Denunciar

0

The code seems to work properly.

var jsonData = ["string 1", "string 2", "test 07 ", "here is test"];

for (var i = 0; i < jsonData.length; i++) {
  $("#ddl_location").append('<option value="' + jsonData[i] + '">' + jsonData[i] + '</option>');
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>

<select class="selectpicker" id="ddl_location">
  <option select="selected">Select Location </option>
</select>

about 4 years ago · Santiago Trujillo Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda