2014-06-17 57 views
0

考慮例如:http://jsfiddle.net/KWLu7/16/計算總體重要性。 Angularjs

我試圖計算整體重要性價值總和每個選擇的選擇的重要性父準則重要性乘以:

var watch = $scope.$watch("prioritizationProfile", function() { 
    $scope.overallImportance = 0; 

    for(var j = 0; j < $scope.prioritizationProfile.length; j++) { 
     var criterionGroup = $scope.prioritizationProfile[j].criterionGroup; 

     for(var i = 0; i < criterionGroup.length; i++) { 

      var criterionChoices = criterionGroup[i].choices; 

      for(var k = 0; k < criterionChoices.length; k++) { 
       console.log(criterionChoices[k]); 
       if(criterionChoices[k].selected) { 
        $scope.overallImportance += 
         criterionChoices[i].importance * 
         criterionGroup[i].importance; 
       } 
      } 
     } 
    } 
}, true); 

如果你嘗試它,你會看到最大值總是22.我在這裏做錯了什麼?

回答

1

您正在使用你的內心錯誤的指數prioritizationProfileWatch

變化

$scope.overallImportance += criterionChoices[i].importance * criterionGroup[i].importance; 

的循環來

$scope.overallImportance += criterionChoices[k].importance * criterionGroup[i].importance; 
+0

是的,你說得對,我忽略了。謝謝! – lexeme