[英]How to select/unselect rows in table?
I have event ng-click()
over each row in table.我在表中的每一行都有事件
ng-click()
。 How to add class new
if I click over a table row and remove class after double click?如果单击表格行并在双击后删除类,如何添加
new
类? I tried to create an array that contents true
/ false
values for each key:我尝试创建一个数组,其中包含每个键的
true
/ false
值:
<div ng-repeat="i in list">
<div ng-click="select(i)"></div>
</div>
$scope.select = function(obj){
$scope.selected[obj.id].show = true;
}
$scope.delete = function(obj){
$scope.selected[obj.id].show = false;
}
You can add a property to your object when clicking on it.单击它时,您可以向对象添加属性。
Try the snippet below and click on a line.试试下面的代码片段,然后单击一行。 It will add the property
selected
to the object.它会将
selected
的属性添加到对象中。
var app = angular.module('myApp', []); app.controller('myCtrl', function($scope) { $scope.list = [{ "name": "A", "description": "foo" }, { "name": "B", "description": "fooo" }]; $scope.select = function(i) { if (i.selected === undefined) i.selected = false; i.selected = !i.selected; } });
.new { background-color: orange; }
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script> <div ng-app="myApp" ng-controller="myCtrl"> <div ng-repeat="i in list"> <div ng-click="select(i)" ng-class="{'new': i.selected}"> {{i.name}} - {{i.description}} </div> </div> </div>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.