AS3 - 排序嵌套数组的数组 [英] AS3 - Sorting an array of nested arrays
问题描述
我怎么会去有关排序嵌套数组的数组的基础上的嵌套数组元素之一的内容是什么?
How would I go about sorting an array of nested arrays, based on the contents of one of the nested arrays elements?
var nestedArray1:Array = new Array(0,0,1);
var nestedArray2:Array = new Array(0,0,9);
var nestedArray3:Array = new Array(0,0,7);
var nestedArray4:Array = new Array(0,0,3);
var parentArray:Array = new Array(nestedArray1,nestedArray2,nestedArray3,nestedArray4);
我想结束了数组排序使用嵌套数组第3部分。
I would like to end up with an array sorted using the nested arrays 3rd element.
所以跟踪sortedParentArray会给我: 0,0,1,0,0,3,0,0,7,0,0,9
So tracing sortedParentArray would give me: 0,0,1,0,0,3,0,0,7,0,0,9
这是nestedArray1,nestedArray4,nestedArray3,nestedArray2
which is nestedArray1, nestedArray4, nestedArray3, nestedArray2
谢谢
标记
推荐答案
既然你可以访问相同的方式数组索引作为属性(阵列[2]
是同数组[2]
),可以使用的 sortOn 。
Since you can access an array index in the same way as a property (array[2]
is the same as array["2"]
) you can use sortOn.
parentArray.sortOn("2", Array.NUMERIC);
您也可以使用其他的指标作为第二或第三排序字段如果不想平等项目的未predictable订单。
You can also use the other indices as second or third sort fields if don't want an unpredictable order for equal entries.
parentArray.sortOn(["2","1","0"], Array.NUMERIC);
这篇关于AS3 - 排序嵌套数组的数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!