alternate element in json array angularjs -


i'm pushing 2 times different data in array :

$scope.numtickets.push({nbuser:data.users[i].name}); 

so retrieve data in view doing :

<ul ng-repeat="user in numtickets track $index">         <li>{{user.nbuser}}</li>         <li>{{user.nbticket}}</li> </ul> 

and few lines after:

$scope.numtickets.push({nbticket:data.tickets.length}); 

and display me this:

enter image description here

and want alternate name , number. should have : claire pagniez 1 michel polnaref 1 mathilde zimmer 3

and here array display in console:

enter image description here

if see code, can see have no choice push first names , ticketnumber. need sort elements alternate name , ticket. here code controller:

$scope.displayuser = function(id) {   var token = "xxxxxxxx";   userdisplay     .send(token, id)     .then(function(data) {       console.log(data);       $scope.userbyorga = data.users;       $scope.numtickets = [];        (i = 0; < data.users.length; i++) {         var userid = data.users;         $scope.numtickets.push({           nbuser: data.users[i].name         });         var userarray = json.stringify(userid);         localstorage.setitem("myid", userarray);       }     })     .then(function() {       var tabuser = json.parse(localstorage.getitem("myid"));       var urls = [];        (i = 0; < tabuser.length; i++) {         urls.push({           url: json.stringify("https://cubber.zendesk.com/api/v2/users/" + tabuser[i].id + "/tickets/requested.json")         });          displayfilter           .user(token, tabuser[i].id)           .then(function(data) {             $scope.numtickets.push({               nbticket: data.tickets.length             });           });       }     }); } 

use user id nested data. @ first request create object each user

        for(i = 0; < data.users.length; i++){              var userid = data.users;             $scope.numtickets[userid] = {nbuser:data.users[i].name}             var userarray = json.stringify(userid);             localstorage.setitem("myid",userarray);         } 

at second request push nbticket user id

       for(i = 0; < tabuser.length; i++){             urls.push({                 url:json.stringify("https://cubber.zendesk.com/api/v2/users/"+tabuser[i].id+"/tickets/requested.json")             });             console.log(urls);             displayfilter                 .user(token,tabuser[i].id)                 .then(function(data){                     $scope.numtickets[tabuser[i].id]['nbticket'] = data.tickets.length                     console.log($scope.numtickets);                  })         } 

you object like

  {      1: {         'nbuser': 'user name1',         'nbticket': '1',       },      2: {         'nbuser': 'user name2',         'nbticket': '2',      }      3: {        'nbuser': 'user name3',        'nbticket': '2',       } } 

Comments

Popular posts from this blog

javascript - How to get current YouTube IDs via iMacros? -

c# - Maintaining a program folder in program files out of date? -

emulation - Android map show my location didn't work -