【发布时间】:2014-05-12 21:11:43
【问题描述】:
我有一个表格的 ng-repeat,我希望能够在单击 <td> 时添加一个类,并在未单击时删除该类。可以同时选择多个<td>。现在所有的城市都在申请或没有申请。
例如:(假设节点有 100 个项目)
<tr ng-repeat node in nodes>
<td>{{node.name}}</td>
<td>{{node.date}}</td>
<td ng-click="toggleMe( node.city )" ng-class"{clicked : isClicked()}" >{{node.city}}</td>
</tr>
在我的 JS 中
$scope.cityArr = [];
$scope.toggleMe = function(city) {
if ($scope.count > 0) {
angular.forEach($scope.cityArr, function(value) {
if (city === value) {
$scope.clicked = false;
} else {
$scope.cityArr.push(city);
$scope.clicked = true;
}
});
} else {
$scope.cityArr.push(city);
$scope.clicked = true;
}
$scope.count = 1;
};
$scope.isClicked = function() {
return $scope.clicked;
};
【问题讨论】:
标签: angularjs ng-class angularjs-ng-class