Jquery sortable('serialize')

KalenGi picture KalenGi · Dec 24, 2009 · Viewed 53.1k times · Source

Is it possible to get the serialized list of items from a UL in jquery by calling the serialize method directly instead of using a callback? The code snippet:

var sortableLinks = $("#category_links_list_3");
var linkOrderData = $(sortableLinks).sortable('serialize');

category_links_list_3 is the id of the UL

The DOM structure is:

<div class="hidden" id="inline_list_3">
    <ul class="category_links_list ui-sortable" id="category_links_list_3">
        <li class="link_title ui-state-default" id="category_link_8">Coconut Oil</li>
        <li class="link_title ui-state-default" id="category_link_9">Hempseed</li>
    </ul>
</div>

Thanks...

Answer

KalenGi picture KalenGi · Dec 24, 2009

I finally got the answer! You need to make the UL sortable first before calling the serialize method on it:

var sortableLinks = $("#category_links_list_3");
$(sortableLinks).sortable();
var linkOrderData = $(sortableLinks).sortable('serialize');

This time linkOrderData contains category_link[]=8&category_link[]=9