2016-11-03 8 views
0

こんにちは、私はJavaスクリプトが新しく、コードのロジックについて助けが必要です。私はCSVから読まれたリストを持っています。今はcsvの他の人が真ん中にいるので、真ん中に現れます。リストに他の人が存在すれば、それが最後に追加されるべきだと私は願っています。 $ scope.disconnectRequestReasonは、私が扱っている配列です。 $ scope.disconnectRequestParameters [i] .paramLabelはotherという値を持つことができます。ロジックを繰り返しながら

if($scope.disconnectRequestParameters[i].paramName == 'disconnectReason'){ 
    $scope.disconnectRequestReason[countReason] = $scope.disconnectRequestParameters[i].paramLabel; 
    countReason++; 
} 

答えて

0

あなたは、配列のサイズを取得し、最後の要素に値を割り当てるには長さ-1を使用する($ scope.disconnectRequestReason [])の長さを使用することができます。複数の「その他」がある場合は、割り当ての数を維持する必要があります。この場合、length - othersCountを使い、それに応じてothersCountをインクリメントします。

あなたのコードは、多かれ少なかれ、この

よう
if($scope.disconnectRequestParameters[i].paramName == 'disconnectReason'){ 

if($scope.disconnectRequestParameters[i].paramLabel == Others){ 
    $scope.disconnectRequestReason[length - othersCount] = $scope.disconnectRequestParameters[i].paramLabel; 
       othersCount++; 
      } else{ 
$scope.disconnectRequestReason[countReason] = $scope.disconnectRequestParameters[i].paramLabel; 
countReason++ 
} 
を見てしまいます
関連する問題