我有items = []的
JSON数据;显示在< tables>中(第1表)使用ng-repeat.然后,用户可以使用ng-repeat $index将此行添加到另一个数组itemsPOS = [],使用push()函数,然后该数组显示在另一个< table>中. (第2表)使用ng-repeat.所以itemsPOS = []数据显示在输入字段中,例如item#,itemDescription,price.在那之后我想做什么,我添加了字段数量,折扣和总计如果我尝试在qty中设置值,它将重新计算总数就像这个plunker:
http://plnkr.co/edit/R3LON9?p=preview.但在我的版本中,它在一个表中.
原文链接:https://www.f2er.com/angularjs/240333.html我现在面临的是如果我为itemsPOS = []添加了两行,如果我编辑第一行数量,则计算第二行总计. **就像下图**
我的代码将项目放在itemsPOS = [];
$scope.passItem = function(index) { var itemNu = $scope.itemLoad[index].itemNo; var descrptn = $scope.itemLoad[index].desc; var cashPrice = $scope.itemLoad[index].cash; var qty = 1; var totalSum = cashPrice*qty; console.log(totalSum) $scope.presyo = cashPrice; $scope.itemsPOS.push({'code':itemNu,'name':descrptn,'price': cashPrice,'qty': qty,'dscnt': 0,'subTotal': totalSum}); console.log($scope.itemsPOS) $scope.counter = $scope.itemsPOS.length;
总计算代码
$scope.changeQty = function(qty) { $scope.qnty = qty; if($scope.qnty>0){ $scope.totalAmount = $scope.presyo*$scope.qnty; } console.log($scope.totalAmount) }
UPDATE
第一张桌子
<tbody> <tr dir-paginate="it in itemLoad|orderBy:sortKey:reverse|filter:search|itemsPerPage:10"> <td><button type="button" class="btn btn-primary btn-sm" title="Add to POS tab" ng-click="passItem($index)"><i class="fa fa-plus-circle"></i> Add</button></td> <td><a href="#">{{it.itemNo | ifEmpty: 'Item No.'}}</a></td> <td>{{it.desc | ifEmpty: 'Item Name.'}}</td> <td>{{it.Available | ifEmpty: '0'}}</td> <td>{{it.OnOrder | ifEmpty: '0'}}</td> <td>₱{{it.cash|currency:''| ifEmpty: '0.00'}}</td> <td>₱{{it.charge|currency:''| ifEmpty: '0.00'}}</td> <td>₱{{it.str|currency:''| ifEmpty: '0.00.'}}</td> <td>₱{{it.ins|currency:''| ifEmpty: '0.00'}}</td> </tr> </tbody>
第二张桌子
<tbody> <tr ng-repeat="so in itemForPOS|filter:search"> <td><button type="button" class="btn btn-danger btn-sm" title="Add to POS tab" ng-click="remItem($index)"><i class="fa fa-times-circle-o"></i> remove</button></td> <td>{{so.code | ifEmpty: 'Item No.'}}</td> <td>{{so.name | ifEmpty: 'Item Name.'}}</td> <td><a><input type="text" value="{{so.price|currency:'₱'}}" style="text-align: center; border: 0;width: 100px" ></a></td> <td><a><input type="text" ng-validate="integer" ng-model="qty" ng-change="changeQty(qty)" placeholder="0" style="text-align: center; border: 0;width: 100px"></a></td> <td><a><input type="text" ng-validate="integer" ng-model="dscnt" style="text-align: center; border: 0;width: 100px" placeholder="0"></a></td> <td><b>{{totalAmount|currency:'₱'}}</b></td> </tr> </tbody>