Angularjs 如何从表行计算合计结果中的结果汇总
我能够计算两个输入并将结果保存在结果输入中并添加新行, 但我想在total result中计算结果值的摘要(此输入不在tr范围内) 移动Angularjs 如何从表行计算合计结果中的结果汇总,angularjs,Angularjs,我能够计算两个输入并将结果保存在结果输入中并添加新行, 但我想在total result中计算结果值的摘要(此输入不在tr范围内) 移动 $scope.Total = total 退出for循环并放置 $scope.rvm.push({}) 在addRow1函数的末尾 您的函数应该如下所示 $scope.addRow1 = function (index) { $scope.rvm[index].result = $scope.rvm[index].val1 - $scope.r
$scope.Total = total
退出for循环
并放置
$scope.rvm.push({})
在addRow1
函数的末尾
您的函数应该如下所示
$scope.addRow1 = function (index) {
$scope.rvm[index].result = $scope.rvm[index].val1 - $scope.rvm[index].val2;
var total = 0;
for (var i = 0; i < $scope.rvm.length; i++) {
total += parseInt($scope.rvm[i].result);
}
$scope.Total = total;
$scope.rvm.push({});
}
$scope.addRow1=函数(索引){
$scope.rvm[index].result=$scope.rvm[index].val1-$scope.rvm[index].val2;
var合计=0;
对于(变量i=0;i<$scope.rvm.length;i++){
总计+=parseInt($scope.rvm[i].result);
}
$scope.Total=总计;
$scope.rvm.push({});
}
移动
$scope.Total = total
退出for循环
并放置
$scope.rvm.push({})
在addRow1
函数的末尾
您的函数应该如下所示
$scope.addRow1 = function (index) {
$scope.rvm[index].result = $scope.rvm[index].val1 - $scope.rvm[index].val2;
var total = 0;
for (var i = 0; i < $scope.rvm.length; i++) {
total += parseInt($scope.rvm[i].result);
}
$scope.Total = total;
$scope.rvm.push({});
}
$scope.addRow1=函数(索引){
$scope.rvm[index].result=$scope.rvm[index].val1-$scope.rvm[index].val2;
var合计=0;
对于(变量i=0;i<$scope.rvm.length;i++){
总计+=parseInt($scope.rvm[i].result);
}
$scope.Total=总计;
$scope.rvm.push({});
}
我看过你的代码。我为total添加了一个计数器,它在每个add事件发生后聚集total,计算运行中的总计。我将其传递给表外的$scope
变量
在控制器中
$scope.outsidetotal = 0; //outside of table scope
$scope.rvm = [{}];
var total = 0;
$scope.total = 0;
$scope.addRow1 = function (index) {
$scope.rvm[index].result = $scope.rvm[index].val1 - $scope.rvm[index].val2;
$scope.rvm.push({})
$scope.outsidetotal = $scope.total += $scope.rvm[index].result;
}
我看过你的代码。我为total添加了一个计数器,它在每个add事件发生后聚集total,计算运行中的总计。我将其传递给表外的$scope
变量
在控制器中
$scope.outsidetotal = 0; //outside of table scope
$scope.rvm = [{}];
var total = 0;
$scope.total = 0;
$scope.addRow1 = function (index) {
$scope.rvm[index].result = $scope.rvm[index].val1 - $scope.rvm[index].val2;
$scope.rvm.push({})
$scope.outsidetotal = $scope.total += $scope.rvm[index].result;
}
尝试使用手表
在addRow1函数中添加以下行:
$scope.$watchCollection("rvm", function() {
$scope.Total = total();
});
然后创建一个函数total()并获取所有结果值的总和
function total() {
var totalNumber = 0;
for(var i=0; i<$scope.rvm.length; i++){
totalNumber = totalNumber + parseInt($scope.rvm[i].result);
}
return totalNumber;
}
函数总数(){
var totalNumber=0;
对于(var i=0;i尝试使用watch
在addRow1函数中添加以下行:
$scope.$watchCollection("rvm", function() {
$scope.Total = total();
});
然后创建一个函数total()并获取所有结果值的总和
function total() {
var totalNumber = 0;
for(var i=0; i<$scope.rvm.length; i++){
totalNumber = totalNumber + parseInt($scope.rvm[i].result);
}
return totalNumber;
}
函数总数(){
var totalNumber=0;
对于(var i=0;i