Sort(a,b) doesn not work in Dojo.dnd.source

I try to sort the data after user drop an element on target container, here is the sorting event

......
var elements_container= dojo.dnd.Source("elements_container");
dojo.byId("elements_container").innerHTML = '';

... // add elements into container...

function sortDnD(){
    // actually full class name is ".element dojoDndItem" to query
    dojo.query(".element",  dojo.byId("elements_container")).sort(
        function( a,b ) {  
            // fire bug debugging cursor skip this section
            var divs_a = dojo.query('> div.sequence', a)
            var diValue_a = divs_a[0].innerHTML;
            var divs_b = dojo.query('> div.sequence', b)
            var diValue_b = divs_b[0].innerHTML;
                return (divs_a == divs_b ? 0 : (a.divs_a > b.divs_b ? 1 : -1));
        }
    ).forEach(// fire bug debugging cursor move to this section
        function(a, idx) { 
            dojo.byId("element_container").insertBefore(a, dojo.byId("elements_container").childNodes[idx]);  
    });
}

dojo.byId("elements_container") is the dojo dnd source. I can guarantee that there are several elements in the containers...

I am using dojo1.6, interestingly when I debug by firebug, it looks the body inside of

function( a,b ) {  
    ....
}

never executed, nor get any error message; the debug cursor move to .forEach just after function( a,b ) but the body of .forEach method runs without any problem. It looks the sort function give no response at all.... any hints is appreciated.

UPDATE

here is the code to invoke above sorting function

dojo.connect( source_container, "onDndDrop", function( source, nodes, copy, target ) {
    nodes.forEach(function(node) {
         sortDnD();
    });
});

UPDATE2

After I change

dojo.query(".element",  dojo.byId("elements_container")).sort(

to

dojo.query(".element",  elements_container).sort(

Dojo gives:

TypeError: root.getElementsByClassName is not a function
...ag){var ret=_201(0,arr),te,x=0;var tret=root.getElementsByClassName(_235);while(...

and here is the dom data for elements_container

node: div#elements_container.container.dnd-list.dojoDndContainer.dojoDndSource.dojoDndTarget
childrenNodes: NodeList[div#dojoUnique23.element.dojoDndItem, div#dojoUnique24.element.dojoDndItem, .....

The reason why the callback in the sort is not being called is because your query selector returns an empty array (therefore you have nothing to sort on).

Use the following instead :

dojo.query(".element.dojoDndItem", "elements_container").sort(

Note that initially your selector was ".element .dojoDndItem" which means "find all nodes with class dojoDndItem that are children of nodes with class element". Here, both classes are in the same nodes, so you need to remove the space and make the selector be ".element.dojoDndItem".

链接地址: http://www.djcxy.com/p/60460.html

上一篇: 设置Paintbox的字体大小会导致调用OnPaint

下一篇: 排序(a,b)在Dojo.dnd.source中不起作用