Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angularjs/22.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 嵌套ng重复中的聚合_Javascript_Angularjs_Ng Repeat - Fatal编程技术网

Javascript 嵌套ng重复中的聚合

Javascript 嵌套ng重复中的聚合,javascript,angularjs,ng-repeat,Javascript,Angularjs,Ng Repeat,我想创建每个taskAssembly对象的taskAssembly.labour的总和,并将其放入TotalAbour字段中 看看这个笨蛋 请参见我的数据: { "client": "client1","takeoff": [{ "taskName": "ToW", "taskQnt": 2300, "totalLabour":"", "taskAssembly": [ { "taskName": "ToW", "taskQnt": 2300, "taskLabou

我想创建每个taskAssembly对象的taskAssembly.labour的总和,并将其放入TotalAbour字段中

看看这个笨蛋

请参见我的数据:

{ "client": "client1","takeoff": [{
"taskName": "ToW",
 "taskQnt": 2300,
"totalLabour":"",
"taskAssembly": [
  {
    "taskName": "ToW",
    "taskQnt": 2300,
    "taskLabour": 22,
    "taskAssembly": [
  { "qnt": 2300, "product": "non-INT", "labour": 12, "application":      "spray" },
  { "qnt": 2300, "product": "non-INT", "labour": 10, "application": "strips" }
    ]
  },
      {
       "taskName": "Pens",
       "taskQnt": 43,
        "taskLabour": 23,
        "taskAssembly": [
           { "qnt": 43, "product": "non-INT", "labour": 23, "application": "spray" }
           ]
       }
    ]}
我的代码不能完全满足我的需要

      $scope.getTotalLabour = function(){
    var total = 0;
    for(var i = 0; i < $scope.estimate.takeoff.length; i++){
      var item = $scope.estimate.takeoff[i];
      total += (item.taskLabour);
    }
    return $scope.estimate.totalLabour = total;
  }
$scope.getTotalabour=function(){
var合计=0;
对于(变量i=0;i<$scope.estimate.takeoff.length;i++){
变量项=$scope.estimate.takeoff[i];
总计+=(项目任务人工);
}
返回$scope.estimate.totalAbour=total;
}
你知道我该怎么做吗?

查看工作演示:

只需创建一个嵌套循环,如:

for(var i = 0; i < $scope.estimate.takeoff.length; i++){
  var total = 0;
  var item = $scope.estimate.takeoff[i];
  console.log(item);
  for (var j = 0; j < item.taskAssembly.length; j++) {
    total += (item.taskAssembly[j].labour);
  }
  item.totalLabour = total;
}
for(变量i=0;i<$scope.estimate.takeoff.length;i++){
var合计=0;
变量项=$scope.estimate.takeoff[i];
控制台日志(项目);
对于(var j=0;j
谢谢您的回复。我道歉,因为我没有正确解释我想做什么。在您提供的演示中,我希望拖线旁边的两个嵌套行的和应该是22,Pens旁边的两行的和应该是43。谢谢。我不得不解析总数,结果成功了。我很高兴。在演示中,数据是数字格式的,因此无需
parseInt