我不知道为什么突然间这开始了,但对于我的生活,我无法理解。这段代码一直在工作,现在我突然得到了这个。
在我的$ q.all()语句中,我处理所有返回的结果并将它们分配给一个新数组。处理完成后,我将新数组打印到控制台,并在我的结果中看到重复的条目。
var newResults = [] ;
return $q.all([promise1(),promise2(),promise3(),promise4()])
.then(function(response) { // response is an array of arrays of objects
// flatten results
var z=0 ;
for (var y=0;y<response.length;y++) { //array of all results
for (var x=0;x<response[y].length;x++) { // array of each result
newResults.push(response[y][x]) ;
console.log(newResults[z]) ;
z++ ;
}
}
console.log("SHOW RESULTS") ;
console.log(newResults) ;
}) ;
请注意,两个console.log语句之间几乎没有任何更改或更改数组的内容。但请看下面的输出:
{vendorID: 0, vendor: "Company AAA", serviceType: 0, serviceSwitch: 1, serviceClass: "standard", …}
{vendorID: 1, vendor: "Company AAA", serviceType: 0, serviceSwitch: 1, serviceClass: "standard", …}
{vendorID: 2, vendor: "Company AAA", serviceType: 0, serviceSwitch: 1, serviceClass: "standard", …}
{vendorID: 3, vendor: "Company AAA", serviceType: 0, serviceSwitch: 1, serviceClass: "standard", …}
{vendorID: 4, vendor: "Company AAA", serviceType: 0, serviceSwitch: 1, serviceClass: "standard", …}
{vendorID: 5, vendor: "Company AAA", serviceType: 0, serviceSwitch: 1, serviceClass: "enhanced", …}
{vendorID: 6, vendor: "Company AAA", serviceType: 0, serviceSwitch: 1, serviceClass: "standard", …}
{vendorID: 7, vendor: "Company AAA", serviceType: 0, serviceSwitch: 1, serviceClass: "standard", …}
{vendorID: 8, vendor: "Company AAA", serviceType: 0, serviceSwitch: 2, serviceClass: "standard", …}
{vendorID: 9, serviceType: 0, vendor: "Company BBB", serviceSwitch: 1, serviceClass: "standard", …}
{vendorID: 10, serviceType: 0, vendor: "Company BBB", serviceSwitch: 1, serviceClass: "standard", …}
{vendorID: 11, serviceType: 0, vendor: "Company BBB", serviceSwitch: 1, serviceClass: "enhanced", …}
{vendorID: 12, serviceType: 0, vendor: "Company BBB", serviceSwitch: 1, serviceClass: "vip", …}
{vendorID: 13, serviceType: 0, vendor: "Company BBB", serviceSwitch: 1, serviceClass: "standard", …}
{vendorID: 14, serviceType: 0, vendor: "Company BBB", serviceSwitch: 1, serviceClass: "standard", …}
{vendorID: 15, serviceType: 0, vendor: "Company DDD", serviceSwitch: 0, product_id: "N/A", …}
{vendorID: 16, serviceType: 0, vendor: "Company FFF", serviceSwitch: 0, product_id: "N/A", …}
{vendorID: 17, serviceType: 0, vendor: "Company GGG", serviceSwitch: 0, product_id: "N/A", …}
{vendorID: 18, serviceType: 1, vendor: "Company HHH", serviceSwitch: 1, service_type: 1, …}
{vendorID: 19, serviceType: 0, vendor: "Company III", serviceSwitch: 0, product_id: "N/A", …}
{vendorID: 20, serviceType: 0, vendor: "Company CCC", serviceSwitch: 1, serviceClass: "standard", …}
{vendorID: 21, serviceType: 0, vendor: "Company CCC", serviceSwitch: 1, serviceClass: "enhanced", …}
{vendorID: 22, serviceType: 0, vendor: "Company JJJ", serviceSwitch: 0, product_id: "N/A", …}
{vendorID: 23, serviceType: 0, vendor: "Company KKK", serviceSwitch: 0, product_id: "N/A", …}
{vendorID: 24, serviceType: 0, vendor: "Company LLL", serviceSwitch: 0, product_id: "N/A", …}
在上面,当我展开每个对象时,NO $$ hashkey被分配给任何对象。
SHOW RESULTS
0:{vendorID: 20, serviceType: 0, vendor: "Company CCC", serviceSwitch: 1, serviceClass: "standard", …}
1:{vendorID: 10, serviceType: 0, vendor: "Company BBB", serviceSwitch: 1, serviceClass: "standard", …}
2:{vendorID: 3, vendor: "Company AAA", serviceType: 0, serviceSwitch: 1, serviceClass: "standard", …}
3:{vendorID: 1, vendor: "Company AAA", serviceType: 0, serviceSwitch: 1, serviceClass: "standard", …}
4:{vendorID: 8, vendor: "Company AAA", serviceType: 0, serviceSwitch: 2, serviceClass: "standard", …}
5:{vendorID: 7, vendor: "Company AAA", serviceType: 0, serviceSwitch: 1, serviceClass: "standard", …}
6:{vendorID: 0, vendor: "Company AAA", serviceType: 0, serviceSwitch: 1, serviceClass: "standard", …}
7:{vendorID: 0, vendor: "Company AAA", serviceType: 0, serviceSwitch: 1, serviceClass: "standard", …}
8:{vendorID: 11, serviceType: 0, vendor: "Company BBB", serviceSwitch: 1, serviceClass: "enhanced", …}
9:{vendorID: 5, vendor: "Company AAA", serviceType: 0, serviceSwitch: 1, serviceClass: "enhanced", …}
10:{vendorID: 21, serviceType: 0, vendor: "Company CCC", serviceSwitch: 1, serviceClass: "enhanced", …}
11:{vendorID: 18, serviceType: 1, vendor: "Company HHH", serviceSwitch: 1, service_type: 1, …}
12:{vendorID: 12, serviceType: 0, vendor: "Company BBB", serviceSwitch: 1, serviceClass: "vip", …}
13:{vendorID: 12, serviceType: 0, vendor: "Company BBB", serviceSwitch: 1, serviceClass: "vip", …}
14:{vendorID: 4, vendor: "Company AAA", serviceType: 0, serviceSwitch: 1, serviceClass: "standard", …}
15:{vendorID: 13, serviceType: 0, vendor: "Company BBB", serviceSwitch: 1, serviceClass: "standard", …}
16:{vendorID: 6, vendor: "Company AAA", serviceType: 0, serviceSwitch: 1, serviceClass: "standard", …}
17:{vendorID: 14, serviceType: 0, vendor: "Company BBB", serviceSwitch: 1, serviceClass: "standard", …}
18:{vendorID: 19, serviceType: 0, vendor: "Company III", serviceSwitch: 0, product_id: "N/A", …}
19:{vendorID: 17, serviceType: 0, vendor: "Company GGG", serviceSwitch: 0, product_id: "N/A", …}
20:{vendorID: 24, serviceType: 0, vendor: "Company LLL", serviceSwitch: 0, product_id: "N/A", …}
21:{vendorID: 23, serviceType: 0, vendor: "Company KKK", serviceSwitch: 0, product_id: "N/A", …}
22:{vendorID: 22, serviceType: 0, vendor: "Company JJJ", serviceSwitch: 0, product_id: "N/A", …}
23:{vendorID: 16, serviceType: 0, vendor: "Company FFF", serviceSwitch: 0, product_id: "N/A", …}
24:{vendorID: 15, serviceType: 0, vendor: "Company DDD", serviceSwitch: 0, product_id: "N/A", …}
在显示“显示结果”后,查看结果,数组索引6和7重复...当我展开这些结果时,我看到以下内容,6&amp; 7 $$ hashkey的重复,然后从结果索引8开始,并且没有分配$$ hashkey。另外,为什么angularJS会以这样的随机顺序重新排列整个数组?
5:
$$hashKey: "object:97"
vendorID: 7
6:
$$hashKey:"object:98"
vendorID: 0
...
7:
$$hashKey:"object:98"
vendorID: 0
8:
vendorID: 11
...
...
...
世界上有什么可能造成这种情况?更重要的是......我该怎么办呢?