AngularJS中获取ng-repeat动态生成的ng-model值

no-repeat  循环生成的购物车,当选择或取消选择选项时通过服务提交到后台

找到这篇文章 

http://blog.csdn.net/itfootball/article/details/51455839


html代码

 <div   ng-repeat="item in Carts.CartItemList"  >
    <input type="checkbox"   ng-model="$parent.Carts.CartItemList[$index].Selected"   ng-click="itemcheck($event)">
</div>



js代码:    

    var app = angular.module('cartApp', []);
        app.controller('cartCtrl', function ($scope, CartService) {
 $scope.Carts = {};
  CartService.GetCart().then(function (json) {
                  view(json, $scope);
              }).finally(function () {
                  
                  loading.modal("hide");
              });

  $scope.itemcheck = function () {

                  loading.modal("show");
		//传参 产品 pid和选择状态($scope.Carts.CartItemList[this.$index].Selected)
                  CartService.selectCart(this.item.PId, $scope.Carts.CartItemList[this.$index].Selected).then(function (json) {
                      view(json, $scope);
                  }).finally(function () {
                      loading.modal("hide");
                  });
              }
});

重点是: $scope.Carts.CartItemList[this.$index].Selected 

这句可以找到对应的表单


json大致结构

{"TotalCount":3,"CartItemList":[{"PId":1,"Selected":false,...},{"PId":2,"Selected":true,...}]}


  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值