1
我無法找到一種方式來循環瀏覽json對象數組。以ng-repeat角度循環遍歷一個對象數組
我的陣列看起來像在螢火(每個系列的對象具有的索引值。):
[[0], Object { idliste=0, id=1, photo="pot.jpg", plus...}, Object { idliste=0, id=3, photo="pot.jpg", plus...}]
[[1], Object { idliste=1, id=1, photo="pot.jpg", plus...}, Object { idliste=1, id=3, photo="pot.jpg", plus...}]
[[2], Object { idliste=2, id=1, photo="pot.jpg", plus...}, Object { idliste=2, id=3, photo="pot.jpg", plus...}]
已經由此代碼生成:
var idListe = $scope.getIdListe();
$scope.listeCommandes[idListe]= new Array([idListe]);
for (i=0;i<$scope.panier.length;i++){
$scope.listeCommandes[idListe].push({
idliste:idListe,
id: $scope.panier[i].id,
photo: $scope.panier[i].photo,
nom: $scope.panier[i].nom,
quantite:$scope.panier[i].quantite,
prix: $scope.panier[i].prix,
heureajout:$scope.getHeure()
});
};
$scope.getIdListe = function(){
var idListe = $scope.listeCommandes.length;
return idListe;
};
和HTML是:
<div ng-repeat="idliste in listeCommandes" >
<div ng-repeat="(nom, id) in idliste">
{{nom}} : {{id}}
</div>
</div>
它不起作用。我真的不知道如何使它工作,這意味着,只需按照索引號打印每個對象即可。
謝謝你,如果你有任何想法。我搜索了論壇,但找不到任何解決方案。也許這是我創建一個錯誤的索引的方式?
能否請您創建一個plukr /小提琴,它真的很難通過觀察代碼 – 2015-04-05 10:32:31
好理解!謝謝。 – 2015-04-05 10:39:57