这是我动态添加行的脚本。我想在一个结果中对每个总结果求和。如何对每个结果求和,添加行和删除行。
//start
$scope.total = function () {
var totalt = 0;
angular.forEach ($scope.dataInvoce.Invoicetoitem.items, function (item) {
totalt += item.quantity * item.price * (1 - item.discount / 100);
});
return totalt;
};
//finish//This is script perfect work, but i have problem in my console/TypeError: Cannot read property 'Invoicetoitem' of undefined/
HTML:
<div class="container">
<div class="row">
<form>
<tr><th>№</th><th>Артикул</th><th>Мярка</th><th>Количество</th><th>Отстъпка %</th><th>Цена</th><th>Ст-ст</th><th></th></tr>
<tr class="clone" ng-repeat="dataItem in dataInvoce.Invoicetoitem.items track by $index">
<td class="number">{{$index+1}}</td>
<td><input type="text" ng-model="dataItem.item.itemName" id="{{$index+1}}" class="tagsItem" ng-change="getItemInvoice($index+1)"></td>
<td><input type="text" ng-model="dataItem.item.solid" size="11" id="solid{{$index+1}}"></td>
<td><input type="text" ng-model="dataItem.quantity" size="10"></td>
<td><input type="text" ng-model="dataItem.discount" size="11"></td>
<td><input type="text" ng-model="dataItem.price" id="price{{$index+1}}"></td>
<td>{{dataItem.quantity*dataItem.price*(1-dataItem.discount/100)|number:2}}</td>
<td><a class="btn btn-default" ng-click="removeItem ($index)">-</a></td>
</tr>
</table>
</div>
<div class="col-md-12 col-sm-12" style="border: 1px solid">
<table class="table table-condensed table-bordered" id="cash">
<tr><td><a class="btn btn-default" id="addnew" ng-click="addItem ()">+</a></td><td></td>
<td class="bank-info"></td>
<td>Данъчна основа </td>
//This is my TaxBase total <td id="sum">{{total()|number:2}}</td>
</tr>
<tr><td></td><td>Словом: <input type="text" ng-model="dataInvoce.leterally"></td>
<td class="bank-info"></td><td>20 % ДДС</td>
//total*0.2 my dds <td id="dds">{{total()*0.2|number:2}}</td>
</tr>
<tr><td></td><td></td><td class="bank-info"></td>
<td>Сума за плащане</td>
//finish general total <td id="total">{{total()+total()*0.2|number:2}}</td>
</tr>
</table>
</div>
<div class="col-md-12 col-sm-10" style="border: 1px solid">
<table class="table table-condensed serviceColor table-bordered">
</form>
</div>
</div>
这是我70%的脚本,另一个信息不是dangerouse
答案 0 :(得分:0)
看起来错误是由未定义的scope.dataInvoce.Invoicetoitem对象引起的。尝试将数组初始化为[]。
//启动
$scope.total = function () {
$scope.dataInvoce = {Invoicetoitem: {items: []}}; //add this line
var totalt = 0;
angular.forEach ($scope.dataInvoce.Invoicetoitem.items, function (item) {
totalt += item.quantity * item.price * (1 - item.discount / 100);
});
return totalt;
};