Moltin Cart,Laravel 和 Angular JS – 遍历 JS 对象
Moltin Cart, Laravel and Angular JS – looping through JS object
我正在使用我想要循环的 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
我想你想做的是:
angular.module('myapp', [])
.controller('MyController', function($scope) {
$scope.objectOfObjects = {
"ASDF": { name: 'First', price: 100 },
"QWER": { name: 'Second', price: 200 },
"FGHJ": { name: 'Third', price: 500 }
}
});
<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>
我正在使用我想要循环的 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
我想你想做的是:
angular.module('myapp', [])
.controller('MyController', function($scope) {
$scope.objectOfObjects = {
"ASDF": { name: 'First', price: 100 },
"QWER": { name: 'Second', price: 200 },
"FGHJ": { name: 'Third', price: 500 }
}
});
<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>