0

I pushed json datas into observable array.I need to get the only the address from ShowData.That means just a string type i need to get the address value based on the position.

ShowData.ts:

 class ShowData{

  constructor(public id:number, public name:string, public address:string, public code:string) {
  }

 }

ts file:

  private arrList: ObservableArray<ShowData> = new ObservableArray<ShowData>();

openData(pos : number){    --->listview item position


   let getValue: any = this.arrList.get(pos);  // this is not worked


}

Based on the listview item position, I need to get only the arrList address.

1
  • ObservaleArray is part of NativeScripts Observables that are not compatible with RxJS's Observables and Angular. Commented Aug 8, 2017 at 11:27

2 Answers 2

1

Observable arrays use .getItem to retrieve the item from array (not .get)

openData(pos : number){   
   let getValue: any = this.arrList.getItem(pos).address;
}
Sign up to request clarification or add additional context in comments.

Comments

1

If you want the address, the following will help

openData(pos : number){    --->listview item position
   let getValue: any = this.arrList[pos].address;
}

6 Comments

this.arrList.getItem(pos).address ;)
in console I'm getting cannot read propery address of undefined. console.log("address", getValue);
are you sure the pos you passed into the function is valid? ie are you sure the pos isnt greater than the array length?
I will check and let you know.
@NicolaeSurdu your comment this.arrList.getItem(pos).address wroked fine.thanks for this answer. Can you post this as an answer?
|

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.