jQuery: How to reverse sortable('serialize') arrays from last to first?

Posted by Binyamin on Stack Overflow See other posts from Stack Overflow or by Binyamin
Published on 2010-05-27T11:54:37Z Indexed on 2010/05/31 17:03 UTC
Read the original article Hit count: 233

The discussion begins http://stackoverflow.com/questions/654535/jquery-what-to-do-with-the-list-that-sortableserialize-returns/2920760#2920760

How to reverse it from last to first, updateList.php?id[]=5&id[]=4&id[]=3&id[]=2&id[]=1&&action=update?

<ul>
<li id="oreder-5">5</li>
<li id="oreder-4">4</li>
<li id="oreder-3">3</li>
<li id="oreder-2">2</li>
<li id="oreder-1">1</li>
<ul>

My code:

$(document).ready(function(){
    order=[];
    $('#list ul').children('li').each(function(idx, elm) { order.push(elm.id.split('-')[1]) });
    $.post('updateList.php', {'order[]': order, action: 'update'});

    function slideout(){
        setTimeout(function(){ $("#response").slideUp("slow", function () {}); }, 2000);
    }
    $("#response").hide();
 $(function() {
    $("#list ul").sortable({ opacity: 0.8, cursor: 'move', update: function() {
   var order = $(this).sortable("serialize") + '&action=update'; 
   $.post("updateList.php", order, function(theResponse){
    $("#response").html(theResponse);
    $("#response").slideDown('slow');
    slideout();
   });
    }});             
 });
});

© Stack Overflow or respective owner

Related posts about JavaScript

Related posts about jQuery