我需要做一个切换按钮...当你点击一次时,它会增加总价钱,如果再次点击按钮并“取消选择”它,它将从总数中减去该数量。
我有这个HTML,添加和删除一个类来更改所选按钮的背景颜色 -
<div class="col-md-4" ng-repeat="service in services_data track by $index">
<div ng-class="showDetails[$index] ? 'panel-warning': 'panel-default'" class="panel">
<button ng-click="$parent.showDetails[$index] = !$parent.showDetails[$index]; price(service.price, service.est_time_mins)" class="panel-heading btn"><span class="pull-left badge">$ {{service.price}}</span>{{service.name}}</button>
<div class="panel-body">
{{service.est_time_mins}} mins. {{service.style}}
</div>
</div>
</div>
和这个控制器 -
app.controller('AppointmentController', ['$scope','services', function($scope, services) {
var data = {};
data.fn = 'services';
services.getData(data).success(function(return_data){
console.log(return_data);
$scope.services_data = return_data;
});
var data = {};
data.fn = 'get_barbers';
services.getData(data).success(function(rd){
$scope.barbers = rd;
console.log(rd);
});
$scope.total_price = 0;
$scope.time = 0;
$scope.price = function(price, time){
$scope.total_price = parseInt(price) + parseInt($scope.total_price);
$scope.time = parseInt(time) + parseInt($scope.time);
}
}]);
可能很容易,但我无法绕过它。感谢。
答案 0 :(得分:0)
使用布尔标志:
- (void)buttonDidTap{
[self.performSegueWithIdentifier: "ShowFirstViewController" sender:self];
}