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

98
Vistas
JQuery select2 set default value from an option

I wanna set a default options from result data and my code isn't working. I try to console.log(data) to check the data, but the data is empty. I think, there is a wrong code in mine, at the String.create. I would like to know why this is the case.

var file_bast = String(result.file_bast);
var fileid = Strings.create("<?=$base_url.$page? >/data/fetch_data_file_update/{filebast}", {filebast:file_bast});
 $.ajax({
     type: 'GET',
     url: fileid
 }).then(function (data) {
   console.log(data);
   $('#file_bast').append(new Option(data.id, data.text, true, true)).trigger('change');
          
   $('#file_bast').trigger({
          type: 'select2:select',
            params: {
                  data: data
              }
          });
      });
 
var Strings = {
  create : (function() {
    var regexp = /{([^{]+)}/g;

      return function(str, o) {
        return str.replace(regexp, function(ignore, key){
          return (key = o[key]) == null ? '' : key;
        });
      }
  })()
};

about 4 years ago · Juan Pablo Isaza
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