从 Angular2 nativescript 中的可观察数组中获取字符串值



我将json数据推送到可观察数组中。我需要从 ShowData 获取唯一的地址。这意味着我只需要一个字符串类型,我需要根据位置获取地址值。

ShowData.ts:

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

TS 文件:

private arrList: ObservableArray<ShowData> = new ObservableArray<ShowData>();
openData(pos : number){    --->listview item position

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

}

根据列表视图项目位置,我只需要获取 arrList 地址。

可观察数组使用.getItem从数组中检索项目(不是.get(

openData(pos : number){   
let getValue: any = this.arrList.getItem(pos).address;
}

如果你想要地址,以下内容会有所帮助

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

最新更新