0

일부 정보를 표시하기 위해 ng-repeat를 사용하여 테이블을 작성하고 있습니다. 표시되는 열 중 하나가 '가중치'열입니다. 우리는 모든 무게를 킬로그램 단위로 데이터베이스에 저장하지만 무게를 파운드로 표시 할 수있는 옵션을 사용자에게 제공해야합니다.드롭 다운 기준 ng-repeat의 값 업데이트

사용자가 가중치 단위를 선택할 수있는 드롭 다운 메뉴가 있으며 변경 사항에 따라 표를 업데이트하려고합니다. 그러나, 나는 그것을 작동시키는 데 어려움을 겪고있다.

다음
$scope.ConvertWeights = function() { 
     if ($scope.schedWeight.ID == "I") { 
      $scope.items.Weight = $scope.items.Weight * 2.2046; 
     } else { 
      $scope.items.Weight = $scope.items.Weight/2.2046; 
     } 

    } 

는 제가 현재 시도하고있어의 JSFiddle입니다 : 여기

내 변경 기능을 살펴 (JSFiddle 전체 예)입니다. 비슷한 상황에 처한 사람이 있다면이 방법을 얻는 방법에 대한 조언을 보내 주시면 감사하겠습니다. 감사!

답변

1

함수 업데이트하시기 바랍니다

$scope.ConvertWeights = function() { 
    if ($scope.schedWeight.ID == "I") { 
     angular.forEach($scope.items, function(item){ 
      item.Weight = item.Weight * 2.2046; 
     }) 
    } else { 
     angular.forEach($scope.items, function(item){ 
      item.Weight = item.Weight/2.2046; 
     }) 
    } 
}; 
0

$ scope.items는 항목 컬렉션 (배열)입니다.

$scope.ConvertWeights = function() { 
    if ($scope.schedWeight.ID == "I") { 
     for (var i in $scope.items) 
      $scope.items[i].Weight = $scope.items[i].Weight * 2.2046; 
    } else { 
     for (var i in $scope.items) 
      $scope.items[i].Weight = $scope.items[i].Weight/2.2046; 
    } 
} 

컬렉션 자체가 아닌 각 요소의 Weight 속성을 수정해야합니다.