0

我有以下数组:

packages    Array (@24ff99c1)   
                [99767] Array (@24ff9809)   
                    forceUpload false   
                    length  0   
                    name    "testdocument.indd" 
                    packageId   "99767" 
                    progressStatus  "allowed"   
                    singleItemSize  50582294 [0x303d316]    
                    singleItemUploadedSoFar 17296352 [0x107ebe0]    
                    sortIndex   1338984578952 [0x137c1b33f88]   
                    status  "upload busy"   
                    totalSize   431203849 [0x19b3a609]  
                    uploadedAtm "37015918"  
                    uploadedSoFar   "19719566"  
                [94854] Array (@24ff7fd9)   
                    forceUpload false   
                    length  0   
                    name    "testdocument.indd" 
                    packageId   "16842" 
                    progressStatus  "allowed"   
                    singleItemSize  6344704 [0x60d000]  
                    singleItemUploadedSoFar 6344704 [0x60d000]  
                    sortIndex   1338984606428 [0x137c1b3aadc]   
                    status  "upload busy"   
                    totalSize   862407698 [0x33674c12]  
                    uploadedAtm "6344704"   
                    uploadedSoFar   ""  
                length  2   

现在我想根据 sortIndex 对其进行排序。我这样尝试过:

packageData.data.packages.sortOn("sortIndex");

它已排序,但问题是我的索引更改为 0, 1, 2, ... 如下所示:

packages    Array (@24ff99c1)   
                [0] Array (@24ff9809)   
                    forceUpload false   
                    length  0   
                    name    "testdocument.indd" 
                    packageId   "99767" 
                    progressStatus  "allowed"   
                    singleItemSize  50582294 [0x303d316]    
                    singleItemUploadedSoFar 17296352 [0x107ebe0]    
                    sortIndex   1338984578952 [0x137c1b33f88]   
                    status  "upload busy"   
                    totalSize   431203849 [0x19b3a609]  
                    uploadedAtm "37015918"  
                    uploadedSoFar   "19719566"  
                [1] Array (@24ff7fd9)   
                    forceUpload false   
                    length  0   
                    name    "testdocument.indd" 
                    packageId   "16842" 
                    progressStatus  "allowed"   
                    singleItemSize  6344704 [0x60d000]  
                    singleItemUploadedSoFar 6344704 [0x60d000]  
                    sortIndex   1338984606428 [0x137c1b3aadc]   
                    status  "upload busy"   
                    totalSize   862407698 [0x33674c12]  
                    uploadedAtm "6344704"   
                    uploadedSoFar   ""  
                length  2

如何在不丢失索引的情况下对数组进行排序?任何帮助,将不胜感激。

4

2 回答 2

1

你不能。排序改变数组的顺序。您唯一的选择是添加一个包含您希望它拥有的索引的数组项。

于 2012-06-06T12:51:15.510 回答
0

这里的问题是您的数组键是整数。
因为它们是 int ,所以它充当常规数组而不是关联数组。
当您执行 packages[99767] 时,您正在查看索引 99767 处的元素。
通过对数组进行排序,它将从 0 开始您的索引
。您需要更改的是将它们转换为字符串的键。

于 2012-06-07T02:18:04.937 回答