ain*_*12u 6 arrays data-binding angularjs angularjs-ng-repeat
我有使用ng-repeat items=[];显示在<tables>(第1表)中的JSON数据.然后,用户可以使用push()函数将该行添加ng-repeat $index到另一个数组中itemsPOS=[],然后<table>使用ng-repeat 将该数组显示在另一个数组(第2个表)中.因此itemsPOS=[]数据显示在输入字段中,例如item#, itemDescription, price.那我想以后的事,我加场qty,discount而Total如果我尝试把值数量,它会重新计算Total就像这样plunker:http://plnkr.co/edit/R3LON9?p=preview.但在我的版本上,它在一张桌子上.
我现在面临的是如果我添加了两行itemsPOS=[],如果我编辑第一行qty,它会计算第二行总计.**就像下图**
我的代码将项目放在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;
Run Code Online (Sandbox Code Playgroud)
总计算代码
$scope.changeQty = function(qty) {
$scope.qnty = qty;
if($scope.qnty>0){
$scope.totalAmount = $scope.presyo*$scope.qnty;
}
console.log($scope.totalAmount)
}
Run Code Online (Sandbox Code Playgroud)
更新 第一张表
<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>
Run Code Online (Sandbox Code Playgroud)
第二张桌子
<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>
Run Code Online (Sandbox Code Playgroud)
小智 5
而不是传递qntyto changeQty函数,你必须传递整行.只需将索引变量用于ng-repeat参数中,以便可以编辑该特定行中的任何列.
对于Eg,请考虑示例代码,
<div ng-repeat="x in records">
<button ng-click="changeQty(x)">
</div>
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
237 次 |
| 最近记录: |