好的,繼承人的泡菜:綁定值到對象屬性,在一個對象中,在陣列中,AngularJS
im使用納克 - 重複通過菜單項進行迭代:
<!-- 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
}
}];
在此先感謝您的任何見解。
究竟是什麼問題? 「this.id」不起作用? – pixelbits 2014-09-05 04:13:35