How to show data in a pop-up from a json file

0

Hi, I have a json file running on a local server with two client tables and bonuses. The json file called clients with primary key id, I have it in a table. I am trying that when you click on the id of the clients table, it shows in a pop-up the data of that client but taking them from json bonuses.

I have something like that

    <table class="table table-striped results" id="table1">
            <thead>
                <tr id="trstyle">
                    <th>N° Bono</th>
                    <th>Cédula</th>
                    <th>Cliente</th>
                    <th>Valor</th>
                    <th>Saldo</th>
                    <th>Fecha creación</th>
                    <th>Fecha vencimiento</th>
                    <th>Usuario</th>
                    <th>Estado</th>
                    <th>Motivo</th>
                    <th>Canal</th>
                </tr>
                <tr class="warning no-result">
                    <td colspan="4"><i class="fa fa-warning"></i> No result</td>
                </tr>
            </thead>
            <tbody>
                <tr id="trstyle" ng-repeat="x in todos">
                    <td id="thbono"><a ng-click="cargar(x)" ng-href={{"#pop1"}} id="open">{{x.id}}</a></td>
                    <td>{{x.cedula}}</td>
                    <td>{{x.cliente}}</td>
                    <td>{{x.valor}}</td>
                    <td>{{x.saldo}}</td>
                    <td>{{x.fechaCreacion}}</td>
                    <td>{{x.fechaVence}}</td>
                    <td>{{x.usuario}}</td>
                    <td>{{x.estado}}</td>
                    <td>{{x.motivo}}</td>
                    <td>{{x.canal}}</td>
                </tr>
            </tbody>
        </table>
        <ul id="#links"></ul>
        <div id="pop1" class="pop-up" ng-controller="TodoCtrl2">
            <div class="popBox">
                <div class="popScroll">
                    <table class="table table-bordered results" id="table1">
                        <thead>
                            <tr id="trstyle"> 
                                <th>Fecha</th>
                                <th>Número</th>
                                <th>Cédula</th>
                                <th>Cliente</th>
                                <th>Valor</th>
                                <th>Documento</th>
                                <th>Canal</th>
                                <th>Mensaje</th>
                                <th>Usuario</th>
                            </tr>
                        </thead>
                        <tbody>         
                            <tr id="trstyleque" ng-repeat="y in bonos">
                                <td>{{y.creationdate}}</td>
                                <td>{{y.id}}</td>
                                <td>{{y.document}}</td>
                                <td>{{y.client}}</td>               
                                <td>{{y.valor}}</td>
                                <td>{{y.canal}}</td>
                                <td>{{y.canal}}</td>
                                <td>{{y.motivo}}</td>
                                <td>{{y.usuario}}</td>
                            </tr>
                        </tbody>
                    </table>
                </div>

in the js I have something like that.

//Consulta un archivo json para llenar la tabla
var App = angular.module('App', []);

App.controller('TodoCtrl', function($scope, $http) {
 $http.get('http://localhost:3000/clientes/')
 .then(function(res){
  $scope.todos = res.data;                
});

});


//Consulta un archivo json para llenar el pop-up
App.controller('TodoCtrl2', function($scope, $http) {
 $scope.bonos=[];
 $http.get('http://localhost:3000/detalle_Bonos/')
 .then(function(res){
  $scope.bonos = res.data;                
});

$scope.cargar = function(bono){
  console.log(bono);
  $scope.bonos[0] = bono;
}
});

thank you very much

    
asked by Andres Hincapie 18.09.2017 в 17:03
source

2 answers

0

wow, some data is missing such as the structure of your json and the most important thing is that the first json of the second is related, I imagine you want to load data according to the first json, then you should take a tour of the second array and compare it with the id you get when you click on clients.

 <pre><td id="thbono"><a ng-click="cargar(x)" ng-href={{"#pop1"}} id="open">{{x.id}}</a></td></pre>

the load works should be something like this:

<td id="thbono"><a ng-click="cargar(x.id)" ng-href={{"#pop1"}} id="open">{{x.id}}</a></td>

then to get the information and load in the modal or popup is:

   $scope.bono_detalle = [];   
   $scope.cargar = function(id_cliente){
      console.log(bono);
      for(i=0;i<$scope.bonos.length ; i++){
        if($scope.bonos[i].idCliente == id_cliente){
          $scope.bono_detalle.push($scope.bonos[i]);
        }
      } 
    }

Finally in the part where you want to show the bonus, you would simply put this:

<tr id="trstyleque" ng-repeat="y in bono_detalle">
   <td>{{y.creationdate}}</td>
   <td>{{y.id}}</td>
   <td>{{y.document}}</td>
   <td>{{y.client}}</td>               
   <td>{{y.valor}}</td>
   <td>{{y.canal}}</td>
   <td>{{y.canal}}</td>
   <td>{{y.motivo}}</td>
   <td>{{y.usuario}}</td>
 </tr>

and ready, so we show the detail to the person, it would be much better if you show a piece of your json and polish your idea, greetings.

    
answered by 18.09.2017 / 18:14
source
0

{   "customers": [     {       "id": 12131409080,       "cedula": "1040",       "client": "Jhon Smith",       "value": "300000",       "balance": "100000",       "fechaCreacion": "01/09/2016",       "fechaVence": "01/09/2016",       "user": "Angela2",       "state": "active",       "reason": "The subject purchased 3 Tennis 2017 with membership card",       "channel": "application1"     }   ],   "Detail_Bonos": [     {       "id": 12131409080,       "jwttoken": "HER48",       "code": "1234",       "amount": "1234",       "creationdate": "01/09/2016",       "expirationdate": "01/09/2016",       "channel": "1",       "status": "active",       "motivate": "I buy",       "document": "1040",       "msg": "message 1",       "client": "Jhon Smith"     }   ] }

    
answered by 18.09.2017 в 21:15