2017-02-10 4 views
1

JSPページAngularjs data-ng-clickはもう一度動作しません...どうですか?

<form> 
    <table class="countrys" data-name="tableCountry"> 
    <tr bgcolor="lightgrey"> 
    <th>Country ID</th> 
    <th>Country Name</th> 
    </tr> 
    <tr data-ng-repeat="c in allCountrys" 
    data-ng-click="selectedCountry(c, $index);" 
    data-ng-class="getSelectedClass(c);"> 
    <td>{{c.countryId}}</td> 
    <td>{{c.countryName}}</td> 
    </tr> 
    </table> 
</form> 

コントローラ

$scope.selectedCountry = function(country, index){ 
angular.forEach($scope.allCountrys,function(value, key) { 
     if (value.countryId == country.countryId) { 
     $scope.selectedCountry = country; 
     } 
}); 

$scope.selectedRowCountry = index; 
} 


$scope.getSelectedClass = function(country) { 

if ($scope.selectedCountry.countryId != undefined) { 
    if ($scope.selectedCountry.countryId == country.countryId) { 
    return "selected"; 
    } 
} 
return ""; 
}; 

CSS

マイページ上でこのテーブルがある
tr.selected { 
    background-color: #aaaaaa; 
} 

、iは1行を押すと、それは色が変わり、それを選択し、両方の機能に入ります...

しかし、もう一度別の行をクリックすると必ず1行だけになるように、tは文句を言わない...私はちょうどように1行、その後、別のものを選択して、できるようにする習慣理由を、知らない

selectedCountry機能に、だけsgetSelectedClass機能に入ります選択しました

私を助けますか?

答えて

2

あなたは関数として$scope.selectedCountryを定義していますが、selectedCountryをクリックしてください最初の時間で、あなたはNG-クリック機能内$scope.selectedCountry = country;を呼び出すことにより、オブジェクトとして$scope.selectedCountryを作ります。

したがって、スコープ変数をremaneしてください。

$scope.selectedCountry = function(country, index){ 
angular.forEach($scope.allCountrys,function(value, key) { 
    if (value.countryId == country.countryId) { 
    $scope.selectedCountry = country; // rename this scope variable 
    } 
}); 
+0

hu、私はちょうど発見しました。 –

+0

thx男、私を救った.... – aaaaaaaa1

関連する問題