Moltin Cart,Laravel和Angular JS - 循环访问JS对象

时间:2015-01-05 21:12:43

标签: javascript angularjs laravel

我正在使用我想要循环的Moltin Cart,所以我可以在Angular JS中读取它然后

我将购物车加载到变量中,我想<div ng-repeat-start="item in cart.contents">并循环浏览购物车中的商品。

我遇到的问题实际上是一个非常基本的JavaScript问题,如果我console.log cart.contents我得到了这个问题:

Object{ 
   33bb9f991617377b9b8333a79ca9ce2c: Object { ... cart contents... },
   1ba14b804d0d81e49397b004e5f1c6d1: Object { ... cart contents... },
   33bb9f991617377b9b8333a79ca9ce2c: Object { ... cart contents... },
}

有没有办法可以解决这个问题:

  • Laravel
  • Angular JS
  • 或经典JavaScript

1 个答案:

答案 0 :(得分:1)

我认为你要做的是:

&#13;
&#13;
angular.module('myapp', [])
.controller('MyController', function($scope) {
    $scope.objectOfObjects = {
        "ASDF": { name: 'First', price: 100 },
        "QWER": { name: 'Second', price: 200 },
        "FGHJ": { name: 'Third', price: 500 }
    }
});
&#13;
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
<body ng-app="myapp">
    <div ng-controller="MyController">
        When iterating over an object of objects, there is no guarantee about the order:
        <div ng-repeat-start="item in objectOfObjects">{{item.name}}</div>
        <div ng-repeat-end>{{item.price}}<br/><br/></div>
    </div>
</body>
&#13;
&#13;
&#13;