Вопрос

I want to make a dynamic drag n drop reordering, but so far I am stuck at the very beginning.

I want to return the ids of the lis inside the ul to be sorted, but I keep getting back an empty alert box:

<ul id="sort">
    <li id="li1">one</li>
    <li id="li2">two</li>
    <li id="li3">three</li>
    <li id="li4">four</li>
</ul>


$('#sort').sortable({
    update: function() {
        var t = $('#sort').sortable('serialize');
        alert(t);
    }
});
Это было полезно?

Решение

serialize

Note: If serialize returns an empty string, make sure the id attributes include an underscore. They must be in the form: "set_number" For example, a 3 element list with id attributes "foo_1", "foo_5", "foo_2" will serialize to "foo[]=1&foo[]=5&foo[]=2". You can use an underscore, equal sign or hyphen to separate the set and number. For example "foo=1", "foo-1", and "foo_1" all serialize to "foo[]=1".

So add a underscore to the id like

<ul id="sort">
    <li id="li_1">one</li>
    <li id="li_2">two</li>
    <li id="li_3">three</li>
    <li id="li_4">four</li>
</ul>

Demo: Fiddle

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top