How to count json data item ionic2 [edit]


#1

My JSON data

"    RESULT":{
              "FACET":[
                { "@NAME" : "creator", 
                  "@COUNT" : "20",
                  "FACET_VALUES":[
                    {
                      "@KEY":"Book Company1",
                      "@VALUE":"13"},
                    {
                      "@KEY":"Book Company1์",
                      "@VALUE":"10"}],
                { "@NAME" : "lang", 
                  "@COUNT" : "70",
                  "FACET_VALUES":[
                    {
                      "@KEY":"tha",
                      "@VALUE":"33"},
                    {
                      "@KEY":"eng",
                      "@VALUE":"42"}
                   ],
                { "@NAME" : "bnb", 
                  "@COUNT" : "64",
                  "FACET_VALUES":[
                    {
                         .
                         .
                         .

              ] 

I want to counting the amount that @NAME for setting an array for the FACET and showing the KEY per FACET[] which seems to be the end goal.

Yes, you totally know what I meant. But i want output is every @KEY of that FACET[]

Example :

<ion-select [(ngModel)]="refine" (ionChange)="optionsFn();">
            <ion-option value="..." *ngFor="let item of date">{{item["@NAME"]}},({{item["@COUNT"]}})</ion-option>
          </ion-select>
<ion-list>          
          <ion-item *ngFor="let item of foundRepos" (click)="itemClicked($event,item)">
            <h3> {{ item[@KEY"] }}</h3>
          </ion-item>
        </ion-list>

.

optionsFn(): void {
            this.http.get("my_url")
                        .subscribe(data =>{
                                 this.date=data.json().RESULT.FACET; //get @NAME
                        },error=>{
err => console.error(err),
                           () => console.log('getRepos completed')
            );
        console.log(this.date);

            console.log(this.date);
            this.goToapply()
      }

      goToapply(){

       this.http.get("my_url")
                        .subscribe(data =>{
                                 this.foundRepos=data.json().RESULT.FACET[0,1,2,3.4......].FACET_VALUES; ///get @KEY
                        },error=>{
                            console.log(error);
                        } );

      }

from above ion-select is show creator , lang andbnb ,I want to If When I select item ion-option value="..." to keep number of “@NAME

example counting amount of @NAME is 3 and

  • when I selectcreator is ion-option value="..." << is 0
  • when I select lang is ion-option value="..." << is 1
  • when I select bnb is ion-option value="..." << is 2
  • and If i get value ,I take it to goToapply() for set FACET[]

example I select bnb I getvalue =2 and console.log(this.refine); is show 2
take it(2) to let p = this.refine , so thatp = 2
take p to this.foundRepos=data.json().RESULT.FACET[p].FACET_VALUES; for show @KEY in ion-list
example :When I select lang output on ion-list is

tha
eng

.
But I don’t know to set option value="…" to keep number 0,1,2,3 respectively