Angularjs - 如果数量超过可用库存,则停止添加到购物车篮中的所选项目数量

时间:2016-06-30 09:37:17

标签: html angularjs json ng-repeat

这是我的总数量函数,数据由外部json文件填充

             $scope.totalQuantity = function(){
                var total = 0;
                for(count=0;count<$scope.items.length;count++){
                    total += parseInt($scope.items[count].Quantity);
                }
                return total;
            };

这就是我在做ng-repeat

的地方
    <tr  ng-repeat="item in items | filter: searchMaterial | limitTo: 10 "> 
                    <td class="desc-field">{{item.Material}}</td>
                    <td class="desc-field">{{item.Description}}</td>
                    <td class="qty-field" >{{item.ActiveQuantity}}</td>
                    <td class="qty-field">
                        <input type="number"  ng-model="item.Quantity" ng-maxlength="item.ActiveQuantity" />
                            <div class="qty-indication">
                                <img  ng-model="item.Quantity" ng-src="{{companyFileInfo.tickPath}}" ng-show="item.Quantity > 0 && item.Quantity <= item.ActiveQuantity " height="20px" width="20px" ng-click="removeItem(item)">
                                <img  ng-model="item.Quantity" ng-src="{{companyFileInfo.alertPath}}" ng-show="item.Quantity > item.ActiveQuantity" height="20px" width="20px" ng-click="removeItem(item)" >
                            </div>
                    </td>
                </tr>

项目总数:

<h4>
     <strong> Total Items: {{totalQuantity()}}</strong>
</h4>

感谢您的帮助:)

0 个答案:

没有答案