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

135
Views
Pase de matriz multidimensional a Ajax Sortable jQuery

Utilizo la función jQuery ui ordenable. Con este

 $(".draggable-right").sortable({ connectWith: ".connected-sortable", update: function(event, ui) { var ordine_video = $(this).sortable('toArray', { attribute: 'data-id' }); // POST to server using $.post or $.ajax $.ajax({ data: { 'ordine_video': ordine_video, }, type: 'post', dataType: 'json', url: 'save_playlist.php' }); // alert(idsInOrder); console.log(ordine_video); }, }).disableSelection();

Puedo pasar una matriz con atributos: valores de identificación de datos en matrices como

 ["BMPR-00026.mp4", "BMPR-00026.mp4"]

Si quiero pasar una matriz como esta con clave y valor

 {"BMPR-00026.mp4":"value_1", "BMPR-00026.mp4": "value_2"}

como se puede hacer tengo el campo en

 <li class="ui-sortable-handle" data-id="BMPR-00026.mp4" style="" rel="value_1">element</li> <li class="ui-sortable-handle" data-id="BMPR-00026.mp4" style="" rel="value_2">element</li>
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Considera lo siguiente.

 function serializeList(list) { var results = {}; $("li", list).each(function(i, el) { results[$(el).attr("data-id")] = $(el).attr("rel"); }); return results; } $(".draggable-right").sortable({ connectWith: ".connected-sortable", update: function(event, ui) { var ordine_video = serializeList(this); $.ajax({ data: { 'ordine_video': ordine_video, }, type: 'post', dataType: 'json', url: 'save_playlist.php' }); console.log(ordine_video); } }).disableSelection();

Esto crea una función, a la que puede pasar una lista y iterará cada elemento de la lista para crear un objeto.

Hay una advertencia, cada data-id debe ser única. Al igual que:

 { "BMPR-00026.mp4": "value_1", "BMPR-00027.mp4": "value_2" }

Si son iguales, el valor de ese índice se actualizará en lugar de agregar una nueva entrada.

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!