さて、ピクルスはこちらです:
メニュー項目を反復処理するために 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 -->
$index は特定のアイテムにバインドされておらず、配列内の位置だけであるため、カート 'theCart[$index].product.qty' 内のアイテムから値を取得しようとすると問題が発生します。配列内の 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
}
}];
洞察をお寄せいただきありがとうございます。