我在表格的每一行都有事件ng-click()
。如果单击表行并在双击后删除类,如何添加类new
?我尝试创建一个数组,其中包含每个键的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;
}
答案 0 :(得分:1)
您可以在单击对象时为其添加属性。
尝试下面的代码段然后点击一行。它会将属性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;
}
});
&#13;
.new {
background-color: orange;
}
&#13;
<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>
&#13;