我有一些看起来像
的东西aInt[0] = {pk:'1', other:'this', otherother:'that'};
aInt[1] = {pk:'1', other:'this2', otherother:'that2'};
aInt[2] = {pk:'2', other:'thisA', otherother:'thatA'};
aInt[3] = {pk:'3', other:'thisB', otherother:'thatB'};
我想把它变成
aNew[0] = [1 [{other:'this', otherother:'that'},
{other:'this2', otherother:'that2'}];
aNew[1] = [2 [{other:'thisA', otherother:'thatA'}];
aNew[2] = [3 [{other:'thisB', otherother:'thatB'}];
或其他相似之处。也许结果上的语法不正确,但我希望我的意图很明确。随意编辑语法。我想基于我拥有的对象数组中的pk字段的值来关联结果集。在as3
提前致谢。
答案 0 :(得分:1)
for each (var obj:Object in aInt) {
if (aNew[obj.pk] == undefined)
aNew[obj.pk] = [];
aNew[obj.pk].push(obj);
}