0

This is the format of data I am getting. How can I display all key names (i.e key1, key2, key3...) and also the subkeys (i.e subkey1_1, subkey1_2...) and their values?

Array_main=[
            {"key1":[
                      {"subkey1_1":
                        {"key1":"value1","key2":"value2"}
                      },
                      {"subkey1_2":                                                   {"ky1":"value1","ky2":"value2"}
                      },
                     ]
             },
             {"key2":[
                      {"subkey2_1":
                        {"key1":"value1","key2":"value2"}
                      },
                      {"subkey2_2":                                                   {"key1":"value1","key2":"value2"}
                      },
                     ]
             ]},
             {"key3":[]},
              ......
              
              ];

If I use something like:

 <ion-list>  
      <ion-card *ngFor = "let array of array_main">        
  <ion-item>        
    <h2 >{{ array}}</h2>       
  </ion-item>

But I am getting [object Object] in the HTML view. How do I parse to inner objects and display their keys and values in ionic2?

I used pipe , but it is displaying keys as numbers instead i want them to display as key names...

import { Pipe, PipeTransform} from '@angular/core';

@Pipe({
  name: 'pipe'
})


export class ObjectValuesPipe implements PipeTransform {
  transform(obj: any) {
 
    let result = [];
    for (var key in obj) {
      if (obj.hasOwnProperty(key)) {

        result.push(key);
       
      }
    }
    return result;
  }
}
<ion-list>  
      <ion-card *ngFor = "let array of array_main | pipe">        
  <ion-item>        
    <h2 >{{ array}}</h2>       
  </ion-item>

The ouput is 0 , 1,2 ... instead i want it to be like .."key1","key2"...

2

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.