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

111
Vistas
Reorder a JS array based on DOM content

Hello all you fantastic stack individuals.

Im using Dropzone to allow for a gallery upload tool. I've also adapted the Dropzone to use jquery UI sortable to allow the user to reorganise the uploaded images. However, when the user sorts their images, the sortable function does not affect the array of images in the Dropzone.files array.

My Initial Dom

<div class="item" id="1234">
    <img src="image.jpg">
</div>
<div class="item" id="5678">
    <img src="image2.jpg">
</div>
<div class="item" id="9112">
    <img src="image3.jpg">
</div>

The resulting Dropzone array once the images have been uploaded

Dropzone.files:[
    0:[
        id: 1234,
        url:image.jpg
    ],
    1:[
        id: 5678,
        url:image2.jpg
    ],
    2:[
        id: 9112,
        url:image3.jpg
    ]
];

This is the callback function I use when the DOM is sorted using jQuery UI Sortable. Sortable has no effect on the array of images in the Dropzone object. I need to be able to distinguish between the first and last images in this callback function. Either by reordering the files array to match that of the DOM, or by finding a way to check if the current iteration is the first file in the DOM. It's important to note that I need all of the additional information from the files array such as width, height, type and size that are not included in my array example.

callback_function(files){

    //need to re order the files array here to match the DOM order!
    
    jQuery.each(files, function(index, file){

        index == 0 ? do_first_image_validation(file) : do_all_other_images_validation(file);

    }

}
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