gpt4 book ai didi

arrays - angularJS 如何计算输入元素中显示的 ng-repeat 数据

转载 作者:行者123 更新时间:2023-12-04 14:38:53 25 4
gpt4 key购买 nike

我有 items=[]; 的 JSON 数据显示在 <tables> (第一个表)使用 ng-repeat。然后用户可以使用 ng-repeat $index 添加此行到另一个数组 itemsPOS=[]通过使用 push() 函数,这个数组然后显示在另一个 <table> 中(第二个表)使用 ng-repeat。所以itemsPOS=[]数据显示在输入字段中,例如 item#, itemDescription, price .之后我想做什么,我添加了字段 qty , discountTotal如果我尝试将值放入 qty,它会重新计算 Total 就像这个笨蛋一样:http://plnkr.co/edit/R3LON9?p=preview .但在我的版本中,它在一张 table 上。

我现在面临的是如果我为 itemsPOS=[] 添加两行,如果我编辑第一行 qty ,它计算第 2 行总计。 **就像下图**

enter image description here

我的代码将项目放在 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)
}

更新
第1表
<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>

第二 table
<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>

最佳答案

而不是通过 qntychangeQty函数,你必须传递整行。只需将 ng-repeat 中使用的索引变量放入即可在参数中,以便您可以编辑该特定行中的任何列。

例如,考虑示例代码,

 <div ng-repeat="x in records">
<button ng-click="changeQty(x)">
</div>

关于arrays - angularJS 如何计算输入元素中显示的 ng-repeat 数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48858385/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com