Z
Z
Zenko2020-04-25 18:44:31
JavaScript
Zenko, 2020-04-25 18:44:31

How to get sorted array in jquery?

I connect the framework ( https://code.jquery.com/ui/1.12.1/jquery-ui.js ), use sortable for the list. When dragging, an array sortArray should be formed, where order-id is the number in the list, slider-id is the id of the record in the database.
On the mouseup event, I get the old array order, then change again and get the previous array order. How to get up-to-date data? Why is there such a blockage?

var sortArray = new Array();
  $("#sortable").on("mouseup", "li", function () {
    var i = 0;
    $("#sortable")
      .find('input[name="slider-id"]')
      .each(function () {
        ++i;
        sortArray[i] = $(this).attr("value");				
      });
  });

Answer the question

In order to leave comments, you need to log in

1 answer(s)
0
0xD34F, 2020-04-25
@Zenko

No mouseup needed. We open the documentation for the plugin used, see what event handlers are available, select the appropriate one :

$('#sortable').sortable({
  stop() {
    const values = $('input[name="slider-id"]', this).get().map(n => n.value);
  },
});

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question