Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Sortable('toArray') or sortable('serialize')

I read a few questions on Stackoverflow that recommend using serialize() and toArray with sortable() to prepare the data for insertion in a database. However, when I try to pass them to sortable('toArray') or sortable('serialize'), it breaks the code i.e. the list is no longer sortable. Here's a fiddle

http://jsfiddle.net/mjmitche/sTzCS/16/

Does anyone know what I'm doing wrong?

<ul id="sortlist">
        <li id="Vancouver">Vancouver</li>
        <li id="Toronto">Toronto</li>
        <li id="Montreal">Montreal</li>
        <li id="Ottawa">Ottawa</li>
        <li id="Calgary">Calgary</li>
        <li id="Edmonton">Edmonton</li>
        <li id="Winnipeg">Winnipeg</li>
     </ul>​

JavaScript

// also tried $('#sortlist').sortable('serialize);

var result = $('#sortlist').sortable("toArray");

alert(result); 
like image 989
BrainLikeADullPencil Avatar asked Sep 16 '12 00:09

BrainLikeADullPencil


1 Answers

This is how to do it

$("#sortlist").sortable({stop: function(event, ui) {
    result = $("#sortlist").sortable("toArray");
     alert(result.length);

}});
like image 75
BrainLikeADullPencil Avatar answered Oct 09 '22 19:10

BrainLikeADullPencil