开发者

SortOn an m-array of objects

Alright, so I have an m-array (Or an array of arrays in actionscript as it doesn't really have m-arrays) and each array in the superarray has a number of objects created at different times in it. I want to sort the superarray by in descending order of the value of the "time" paramater of the object at index 0 in each subarray.

I've tried

开发者_运维百科
superarray.sortOn([0].time, Array.DESCENDING);

and

superarray.sortOn("0.time", Array.DESCENDING);

but this doesn't seem to work. Any suggestions? Will I just have to write my own sort function to do this? If so what's the best way to go about it?


Try using the Array.sort function passing a compare function. Something like this:

var superarray:Array = [
    [{time:900}, {time:715}, {time:655}],
    [{time:450}, {time:333}, {time:100}],
    [{time:999}, {time:75}, {time:30}]
    ];
var sorted:Array = superarray.sort( function(A:Array,B:Array):int {
    return ObjectUtil.numericCompare(A[0].time, B[0].time);
    });
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜