Problem with order, deleted and push array

Hello community, I am having an arrangement json from a query to a webservice. So far so good, I’m showing this data THROUGH ionic an accordion. What I need is to eliminate all elements of groups that are created and re-generate them.

I am having trouble removing all elements of groups, are not deleted and do not load properly. I leave my code as I unfold the data.

$scope.estadisticasParticipanteIntervalo = function(tagid,id){
if(navigator.onLine){
  var ids = '';
  lista_corredores = misCorredoresService.getCorredores();
  for (var i = 0; i < lista_corredores.length; i++) {
    if(i==0){
      ids = lista_corredores[i].id+",";
    }else{
      ids+= lista_corredores[i].id+",";
    }
  }
  $http({method: 'GET', url: URL_ESTADISTICAS+'appId='+appId+'&token='+tokenApp+'&id='+ids})
  .success(function(data){
    if(data.error){
      if(data.error.type=="no_results" && data.error.msg=="No splits found"){
          
      }
    }
    for (var p = 0; p <data.data.length-1; p++) {
      for(var i = $scope.groups.length - 1; i >= 0; i--){
          $scope.groups[i].items.splice(i,1);
      }
      respuestas = data.data[p].list;
      resp = respuestas;
      resp.url = '';
      if(data.data[p].url !== undefined){
        resp.url = data.data[p].url;
        //$scope.groups[i].url = data.data[i].url;
      }
      $scope.groups[p].items.push(resp);
    } 
  })
  .error(function(){
    
  });
}
}

This is the view.

<script id="misCorredores.html" type="text/ng-template" ng-controller="MisCorredoresCtrl">
    <ion-view title='{{title}}'>
      <ion-nav-buttons side="left">
      <div class="botonAtrasCorredores">
        <button class="button icon-left ion-arrow-left-c" ng-click="volver()" style="color: #0154a0;background-color:transparent;border:none;border-color:transparent"></button>
      </div>
      </ion-nav-buttons>      
     <ion-content padding="true">
    <center>
     <p style="font-size: 20px;color:#ff6702 !important"class="titulo_busqueda">Mis Corredores<span style="color:#b4b3b2;font-size:12px;">&nbsp;&nbsp;&nbsp;({{total}} de 10)</span></p>
     <br>
    </center>
     <button class="button button-small button-positive" id="boton_editar" style="color:#FFFFFF;margin-left:15px;margin-top:5px;font-family:Entel_2;font-weight:bold;background: #0154a0;border-color: #0154a0;" ng-show="groups.length" ng-click="data.showDelete = !data.showDelete; data.showReorder = false;editar();">Editar</button>
     <button class="button button-small button-positive" id="boton_eliminar_todo" style="float:right;display:none;color:#FFFFFF;margin-right:15px;margin-top:5px;font-family:Entel_2;font-weight:bold;background: #0154a0;border-color: #0154a0;" ng-show="groups.length" ng-click="eliminarTodo();">Eliminar todo</button>
     <br>
     <br>
      <ion-item ng-show="!groups.length" style="border-color: transparent;">
        <center>
          <p style="font-size: 15px;"class="titulo_busqueda">No tienes corredores asociados.</p>
        </center>
        <center style="margin-top:20px">
        <button class="button button-positive" ng-show="!groups.length" style="background-color: #ff6702;color: #FFF;font-family: Entel_2;border-color: #ff6702;" ng-click="buscarCorredores()">
          { busCar cOrredores
        </button>
        </center>
      </ion-item>
      <ion-list show-delete="data.showDelete" show-reorder="data.showReorder">
        <ion-item ng-show="resultados.length" ng-repeat="group in groups" item="task" style="border-color: transparent;background-color:">
        <ion-item id="botonDesplegar" class="item item-avatar corredores_lista" ng-class="{active: isGroupShown(group)}" style="border: 1px solid #DDD !important;background-color:#FFFFFF !important;-webkit-border-radius: 2px;-moz-border-radius: 2px;border-radius: 2px;">
        <ion-option-button class="button-assertive" ng-click="onItemDelete($index,group.id)"><p style="margin-top: 22px;color: white;">Eliminar</p></ion-option-button>
          <img src="img/ciclist_orange.png">
          <h3 style="color:#0073AE;font-weight:bold;">{{group.name}}</h3>
          <p>Número de corredor : <span style="font-weight:bold;">{{group.bib}}</span></p>
          <p style="margin-top: -10px;">Carrera : <span style="font-weight:bold;">{{group.race}}</span></p>
          <i class="icon" style="float: right;margin-top: -60px;margin-right: -10px;" ng-click="toggleGroup(group,group.id,$index,1)" ng-class="isGroupShown(group) ? 'boton_abrir' : 'boton_cerrar'"></i>
        </ion-item>
       <ion-item class="item-accordion" ng-show="isGroupShown(group)" ng-repeat="datos in group.items">
       <button class="button button-small button-positive ion-loop" style="background-color:#ff6702 !important;color:#FFFFFF;font-size:20px;border-color:#ff6702;" ng-click="toggleGroup(group,group.id,$index,0)"></button>
              <div id="datosParticipante" class="datagrid" style="margin-top:10px;">
              <table style="width:100%">
                <thead>
                  <th>Punto</th>
                  <th>Tiempo</th>
                  <th>Hora</th>
                </thead>
                <tbody>
                  <tr ng-repeat="dato in datos" ng-if="dato.label != 'Fin' ">
                     <td>{{dato.label}} </td>
                     <td>{{dato.time}}</td>
                     <td>{{dato.timeOfDay}}</td>
                  </tr>
                  <tr ng-repeat="dato in datos" ng-if="dato.label == 'Fin'" style="background:#A6A6A6;">
                     <td style="color:#FFFFFF;font-weight:bold">{{dato.label}} </td>
                     <td style="color:#FFFFFF;font-weight:bold">{{dato.time}}</td>
                     <td style="color:#FFFFFF;font-weight:bold">{{dato.timeOfDay}}</td>
                  </tr>
                </tbody>
              </table>
            </div>
        <center style="margin-top:20px;" ng-if="datos.url != '' " >
          <button class="button button-positive" style="background-color: #ff6702;color: #FFF;font-family: Entel_2;border-color: #ff6702;">
            {{datos.url}}
          </button>
        </center>
        </ion-item>
        <ion-delete-button class="ion-minus-circled" ng-click="onItemDelete($index,group.id)"></ion-delete-button>
        </ion-item>
      </ion-list>
    <div style="height:50px;"></div>
    </ion-content>
  </ion-view>
</script>

It’s really hard to debug code blocks on the forum. Could you make a codepen or plunker that demonstrates the issue (maybe using hard-coded JSON instead of the webservice)? Then someone might be able to play around with it and give you some ideas.

1 Like

I find it very difficult to create a codepen by plugins and features that I have

not if you hardcode the JSON?

I realized that my code block was wrong and fix and everything works fine. :slight_smile: