1

I'm trying to list some reviews I get from an API built using laravel to show some reviews about some meals, a slideshow about reviews messages and some data as you may see in the array of Objects.

{

    "2": {
        "reviews": [
            {
                "id": 2,
                "title": "Trop bon !",
                "author": 1,
                "text": "Trop bon ! 11 Trop bon !Trop bon !Trop bon !Trop bon !",
                "picture": "",
                "rating": 4.5
            },
            {
                "id": 3,
                "title": "Review 2",
                "author": 1,
                "text": "another review",
                "picture": "",
                "rating": 3
            }
        ],
        "data": {
            "restaurant": {
                "restaurant_id": 1,
                "restaurant_logo": "http://3.bp.blogspot.com/-Oz5XdPqGddQ/ULy9zwbIDXI/AAAAAAAAPio/HZwYtIr7DfE/s1600/22-restaurant-logo-design.jpg",
                "restaurant_title": "Resto BenArus",
                "restaurant_type": "Fast Food",
                "restaurant_lat": "36.7465169",
                "restaurant_lng": "10.2171373",
                "user_distance": 9.3072696748262
            },
            "meal": {
                "id": 2,
                "meal_title": "Spaghetti Bolonaise",
                "price": 50,
                "meal_description": "Epic !",
                "reviews_count": 2,
                "overall_rating": 3.75
            }
        }
    },
    "3": {
        "reviews": [
            {
                "id": 4,
                "title": "Total",
                "author": 1,
                "text": "cristifant ",
                "picture": "https://www.gravatar.com/avatar/d9625431c20a1565a2e06f811a95c36c?s=140&d=retro",
                "rating": 3
            }
        ],
        "data": {
            "restaurant": {
                "restaurant_id": 2,
                "restaurant_logo": "http://3.bp.blogspot.com/-Oz5XdPqGddQ/ULy9zwbIDXI/AAAAAAAAPio/HZwYtIr7DfE/s1600/22-restaurant-logo-design.jpg",
                "restaurant_title": "resto 2",
                "restaurant_type": "Fast Food",
                "restaurant_lat": "10",
                "restaurant_lng": "32",
                "user_distance": 3701.7730713836
            },
            "meal": {
                "id": 3,
                "meal_title": "Hamburger",
                "price": 12,
                "meal_description": "",
                "reviews_count": 1,
                "overall_rating": 3
            }
        }
    }

}

I created a Pipe to iterate through the result :

   transform(value, args:string[]):any {
    let keys = [];
    for (let key in value) {
      keys.push({key: key, value: value[key]});
    }
    return keys;
  }

But it didn't gave any better result, all I'm getting is the first keys of the array :

How data is shown (not pretty sure it is the correct way) :

    <ion-content padding>
  <ion-list *ngFor="let data of search | keyobject " no-lines>
    <ion-list *ngFor="let data2 of data | keyobject " no-lines>
      <ion-item>Value: {{ data2.value }} {{ data2.key }}</ion-item>
      <ion-list *ngFor="let data3 of data2 | keyobject " no-lines>
        <ion-item>Value: {{ data3.value }} {{ data3.key }}</ion-item>
      </ion-list>
    </ion-list>
  </ion-list>
</ion-content>
3
  • You got answer for this? I am having same issue. Please do the needful if you have solution. Commented Sep 29, 2017 at 12:31
  • yes, I just had to do more than that simple itration it's all about dumping the retuned data and transforming to another array Commented Sep 29, 2017 at 12:55
  • @RahulMankar I just posted the code I used as an answer Commented Sep 29, 2017 at 13:01

1 Answer 1

1
<ion-row  responsive-sm wrap *ngFor="let data of meals | ArrayObject " >
    <ion-col >
      <ion-card>
        <ion-row>
          <ion-col col-12 no-margin no-padding>
            <ion-slides>
              <ion-slide *ngFor="let reviews of data.value['reviews'] | ArrayObject " >
                <img src="{{reviews.value['picture']}}"/>
                <h1>{{reviews.value['title']}}</h1><small>{{reviews.value['author']}}</small>
              </ion-slide>
            </ion-slides>
          </ion-col>
          <ion-col col-12 no-margin no-padding>
            <ion-card-content>
              <ion-card-title>
                {{data.value['meal']['title']}}
              </ion-card-title>
              <p>
                <small><rating [score]="data.value['meal']['overall_rating']" [max]="5"></rating> ({{data.value['meal']['reviews_count']}}) Avis</small>
              </p>
            </ion-card-content>
          </ion-col>
        </ion-row>
      </ion-card>
    </ion-col>
  </ion-row>

The difference between the one in the question and this is simply that on the question I directly transformed arrays, but here, I'm using array elements as values, and then transforming them after knowing what they are (E.g. : data.value['reviews'])

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.