添加更改金额并更改Ionic中的复选框中的总计

时间:2016-08-09 15:50:58

标签: angularjs ionic-framework ionic-view

我在Checkbox中创建了一个列表,列出了用户可以选择产品的产品。我需要在产品列表中添加一个选项,用户可以在其中更改所选产品的数量。我怎么能这样做?

我的观点:

<ion-view view-title="Bebidas Adicionais" ng-controller="exBebidasCtrl" >     

 <div class="bar bar-subheader">
      <h2 class="title">{{'Sub-Total R$ ' + getTotalSelected()}}</h2>
</div>

        <ion-refresher pulling-text="Puxe para atualizar..."  on-refresh="doRefresh()"></ion-refresher>
        <ion-list class="card list">
            <div class="item item-input">
                <i class="icon ion-search placeholder-icon"></i>
                <input type="search" ng-model="q" placeholder="Procurar" aria-label="filter bebidasextras" />
            </div>
        </ion-list>

   <ion-list>

       <div ng-repeat="bebida in bebidasextras">
          <ion-checkbox ng-model="bebida.selected" > 
              <h2>{{bebida.ad_bebida_titulo}}</h2>     
              <p>R$ {{bebida.ad_bebida_valor}}</p>
          </ion-checkbox>
       </div>  
</ion-list>      

            <button class="button button-block button-balanced">
                <a  ng-click="addToCart(bebida.ad_bebida_titulo,bebida.ad_bebida_valor)" class="button button-assertive button-clear icon ion-android-cart"> Continuar Comprando </a> 
            </button>     
    </ion-content>      

我的控制器:

    $scope.bebidasextras = [];

var promise = $http.get('http://nhac.esy.es/api_carrinho/lista_bebida_extra.php?json=restaurantes')
  .success(function(retorno) {
    console.log(retorno);
    $scope.bebidasextras = retorno; // não precisa fazer retorno.data

        $scope.user = {
            bebidasextras: [$scope.bebidasextras[1]]
          };
          $scope.checkAll = function() {
            $scope.user.bebidasextras = angular.copy($scope.bebidasextras);
          };
          $scope.uncheckAll = function() {
            $scope.user.bebidasextras = [];
          };
          $scope.checkFirst = function() {
            $scope.user.bebidasextras = [];
            $scope.user.bebidasextras.push($scope.bebidasextras[0]);
          };
          $scope.setToNull = function() {
            $scope.user.bebidasextras = null;
          };

      $scope.getTotalSelected = function() {
      var total = 0;

      for(var i = 0; i < $scope.bebidasextras.length; i++){
        var bebida = $scope.bebidasextras[i];
        total += bebida.selected ? Number(bebida.ad_bebida_valor) : 0;
      }

      return total;
    }

})
.error(function(erro) {        
    console.log(erro);
});

1 个答案:

答案 0 :(得分:1)

您可以使用带+和 - 按钮的输入框。点击哪个用户可以更改所选产品的数量。

如果你可以分享更多细节,我可以用更好的方式回答。