Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

216
Views
Establecer título de valores preseleccionados de Select2

Adjunté valores preseleccionados de Select2 usando AJAX como a continuación.

 $.ajax({ type: 'POST', dataType: 'json', url: "/wordpressbosta/matt/wp-admin/admin-ajax.php", // url: "/wp-admin/admin-ajax.php", data: { element_id: element_id, action: 'get_preselect_values', }, }).then(function (data) { var options = []; if (data) { $.each(data, function (index,text) { options.push(new Option(text['text'], text['id'], true, true)); }); } selectEle.append(options).trigger('change'); }

Me gustaría establecer el title de los valores preseleccionados.

ingrese la descripción de la imagen aquí

Intenté con el siguiente código.

 $.ajax({ type: 'POST', dataType: 'json', url: "/wp-admin/admin-ajax.php", data: { element_id: element_id, action: 'get_preselect_values', }, }).then(function (data) { var options = []; if (data) { $.each(data, function (index,text) { var user_data = '<table> \ <tr> \ <td>Organisation</td> \ <td>'+text[0][1]+'</td> \ </tr> \ <tr> \ <td>Age</td> \ <td>'+ text[0][0]+'</td> \ </tr> \ </table>'; var opt = new Option(text['text'], text['id'], true, true); opt.attr("title",user_data); options.push(opt); }); } selectEle.trigger('change');
about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

Creo que está buscando la opción templateSelection .

 $(".js-example-templating").select2({ templateSelection: formatState, }); function formatState(state) { return $( `<span class='tooltip' title='${state.title}'>${state.text}</span>` ); }

Editar: agregar selectEle.append(opt); antes de desencadenar el cambio

 $.ajax({ type: "POST", dataType: "json", url: "/wp-admin/admin-ajax.php", data: { element_id: element_id, action: "get_preselect_values", }, }).then(function (data) { // var options = []; if (data) { $.each(data, function (index, text) { var user_data = "<table> \ <tr> \ <td>Organisation</td> \ <td>" + text[0][1] + "</td> \ </tr> \ <tr> \ <td>Age</td> \ <td>" + text[0][0] + "</td> \ </tr> \ </table>"; var opt = new Option(text["text"], text["id"], true, true); opt.attr("title", user_data); // options.push(opt); selectEle.append(opt); // added codes }); selectEle.trigger("change"); } });
about 4 years ago · Juan Pablo Isaza Report

0

Pruebe el método de select2 cuando se selecciona un elemento

 $('#example').on('select2:select', function (e) { $(this).attr('title', 'some value title'); });
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!