Question

I m using the jquery add-in nested Sortable to re-sort a list. I was wonderhing how I can determine the parent and position where the node has been inserted into.

My issue is that the serialize function always returns the status of the tree before I updated it. Thus when I move node 1 from position 2 to position 3 and afterwards call serialize it always returns the state of the tree it had before I moved the node.

This is the issue with the build-in serialize functions and some other custom function I found: serialize custom

I m calling the serialize function at the end of the _mouseStop function. Seems as it is not the correct position to do this... Seems as the inner this holds the old state of the tree. Thus the question is probably how can I refresh it..!?

_mouseStop: function(event, noPropagation) {
    ......
    $.ui.sortable.prototype._mouseStop.apply(this, arguments);
    //custom code added
    var ret = this.serialize({startDepthCount: 0});
    console.log(ret);

Whereas when I call the serialize function from a button bound to the serialize function it works fine.

The html structure is similar to the one used in the tutorial:

<ol class="sortable">
        <li id="list_1"><div>Item 1</div>
            <ol>
                <li id="list_2"><div>Sub Item 1.1</div>
                <li id="list_3"><div>Sub Item 1.2</div>
            </ol>
        <li id="list_4" class="no-nest"><div>Item 2 (no-nesting)</div>
        <li id="list_5"><div>Item 3</div>
            <ol>
                <li id="list_6" class="no-nest"><div>Sub Item 3.1 (no-nesting)</div>
                <li id="list_7"><div>Sub Item 3.2</div>
                    <ol>
                        <li id="list_8"><div>Sub Item 3.2.1</div>
                    </ol>
            </ol>
        <li id="list_9"><div>Item 4</div>
        <li id="list_10"><div>Item 5</div>
    </ol>
Était-ce utile?

La solution

The jQuery nestedSortable documentation says "All jQuery Sortable options, events and methods are available". If you take a look at the jQuery UI sortable doc events tab, you'll see update, which I think is the right event for you.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top