好的,继承人的泡菜:绑定值到对象属性,在一个对象中,在阵列中,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