伙计们我想使用sortOn对数组进行排序,我非常困惑,因为我需要一些自定义排序数组方法来实现我的目的,这是我的数组:
var C:Node = new Node(); var D:Node = new Node(); var E:Node = new Node();
var F:Node = new Node(); var K:Node = new Node(); var L:Node = new Node();
//Node is graphic
var myArray:Array = [C, D, E, F, K, L];
C.name = "C"; D.name = "D"; E.name = "E"; F.name = "F"; K.name = "K"; L.name = "L";
C.z = 2; D.z = 1; E.z = 2; F.z = 1; K.z = 1; L.z = 2;
for (var a:int = 0; a<myArray.length; a++) trace(myArray[a].name+".z : "+myArray[a].z);
//Output is :
//C.z : 2
//D.z : 1
//E.z : 2
//F.z : 1
//K.z : 1
//L.z : 2
我想按名称和z值排序myArray [],所以如果我跟踪(); myArray的结果是:
for (var b:int = 0; b<myArray.length; b++) trace(myArray[b].name+".z : "+myArray[b].z);
//output is :
//C.z : 2
//E.z : 2
//L.z : 2
//D.z : 1
//F.z : 1
//K.z : 1
那么,如何使用sortOn()对myArray []进行排序;方法,以匹配我想要的?
答案 0 :(得分:1)
我想你想要这个...
myArray.sortOn( ["z", "name"],[Array.DESCENDING,null]);