Rescue 2 arrays with Angularjs

Asked

Viewed 85 times

0

angular query

app.controller('recipedetails', function($rootScope, $routeParams, $http)
{
 $http.get('app/querys/receita_item.php?id='+$routeParams.id).success(function(data) {
  $rootScope.recipedetails = data;
  console.log(data);
 });
});

Arrays receita_item.php

[{"id":"9","id_produto":"1","forma":"Alface","valor":"1.00","id_lanche":"3","qtd_max":"1"}]
[{"id":"41","name":"dd","value":""},{"id":"42","name":"dd","value":""}]

I need these arrays separated

$rootScope.recipedetails_one = data1; // [{"id":"9","id_produto":"1","forma":"Alface","valor":"1.00","id_lanche":"3","qtd_max":"1"}]

$rootScope.recipedetails_two = data2; // [{"id":"41","name":"dd","value":""},{"id":"42","name":"dd","value":""}]

2 answers

0

You can use the params option of the $http method.

app.controller('recipedetails', ['$scope','$http', function ($scope,$http) {
   $http({

       url: "app/querys/receita_item.php", 
       method: "GET",
       params: {id: $scope.id}

   }).success(function(data, status) {

       $scope.recipedetails = data;

   }).;  
}]);

http://docs.angularjs.org/api/ng.$http#get

  • guy my code pulls correct the data but only for 1 array as it has 2 it does not search...

  • face my code pulls the normal data the problem and that has 2 array on the same page.. ai does not answer the date

  • The solution then is to make a list of objects, where you will put your 2 JSON objects. So it will come the 2 in the same object. Got it ?

  • humm no, in case multi dimensioning this array?

  • I had to post another answer to show you the code. I think your problem is just object organization. Take a look over lists of objects. Thanks

0


In case it would look like this :

[
 [{"id":"9","id_produto":"1","forma":"Alface","valor":"1.00","id_lanche":"3","qtd‌​_max":"1"}], [{"id":"41","name":"dd","value":""}],
 [{"id":"42","name":"dd","value":""}] 
]

http://www.devmedia.com.br/introducao-ao-formato-json/25275

If it’s not that I’m sorry, hugs.

  • ixi mano needed these separate array... because these lists are different

  • Um. But this is not possible. Either you make 2 queries or search a list(collection). There in Success you can scan that list to separate the data. for example : data[0] - to access the first data[1] - to access the second . Or to do a foreach to scan.

  • humm plus 2 search increases page loading time... and when ponhe [0] [1] does not take the first array and neither does the second take the first item of the first array and so on

  • and actually when it has 2 array [{}] it error in angular script

  • Complicated... I do it often. Try as follows: [ [{"id":"9","id_product":"1","shape":"Lettuce","value":"1.00","id_lanche":"3","qtd_max":"1"}], [{"id":"41","name":"dd","value":"}], value[{":"42","name"dd","""""""":"""}] ]

  • gave error: Unexpected token ,

  • humm now was :D worked

  • Very good! Hugging.

  • Thanks @Vinícius!!!!

Show 4 more comments

Browser other questions tagged

You are not signed in. Login or sign up in order to post.