好的,这是泡菜:
我使用 ng-repeat 遍历菜单项:
<!-- start the list/loop -->
<ion-list ng-repeat="this in menuItems.items track by $index" type="item-text-wrap">
<a class="item" ng-click="addToCart({{this}})">{{this.name}}
<span class="badge badge-stable">{{theCart[$index].product.qty}}</span>
</a>
</ion-list>
<!-- end the list/loop -->
当我尝试从购物车 'theCart[$index].product.qty' 中的项目中获取值时会出现问题,因为 $index 未绑定到任何特定项目,只是数组中的位置。我需要获取数组深处的唯一标识符 2 个对象,因此我可以确保通过 Angular 提供的双向数据绑定获得正确的值。
theCart: [{
product: {
id: 1,
section: 'sides',
name: 'mayo',
price: 7,
outOfStock: '',
qty: 1
}
}, {
product: {
id: 0,
section: 'sides',
name: 'ranch',
price: 6,
outOfStock: '',
qty: 1
}
}];
提前感谢您的任何见解。