从angular2 nativescript中的可观察数组获取字符串值
我将json数据推送到可观察数组中。我需要从ShowData中获取唯一的地址。这意味着我需要基于位置获取地址值的字符串类型 ShowData.ts:从angular2 nativescript中的可观察数组获取字符串值,angular,typescript,nativescript,angular2-nativescript,Angular,Typescript,Nativescript,Angular2 Nativescript,我将json数据推送到可观察数组中。我需要从ShowData中获取唯一的地址。这意味着我需要基于位置获取地址值的字符串类型 ShowData.ts: class ShowData{ constructor(public id:number, public name:string, public address:string, public code:string) { } } private arrList: ObservableArray<ShowData>
class ShowData{
constructor(public id:number, public name:string, public address:string, public code:string) {
}
}
private arrList: ObservableArray<ShowData> = new ObservableArray<ShowData>();
openData(pos : number){ --->listview item position
let getValue: any = this.arrList.get(pos); // this is not worked
}
ts文件:
class ShowData{
constructor(public id:number, public name:string, public address:string, public code:string) {
}
}
private arrList: ObservableArray<ShowData> = new ObservableArray<ShowData>();
openData(pos : number){ --->listview item position
let getValue: any = this.arrList.get(pos); // this is not worked
}
private arrList:ObservableArray=new ObservableArray();
openData(位置:编号){->listview项目位置
让getValue:any=this.arrList.get(pos);//这不起作用
}
根据listview项目的位置,我只需要获取arrList地址。如果需要地址,以下内容将有所帮助
openData(pos : number){ --->listview item position
let getValue: any = this.arrList[pos].address;
}
如果您想要地址,以下内容将有所帮助
openData(pos : number){ --->listview item position
let getValue: any = this.arrList[pos].address;
}
可观察数组用于从数组中检索项(而不是。get
)
可观察数组用于从数组中检索项(而不是。get
)
ObservaleArray是与RxJS的ObservaleArray和Angular不兼容的NativeScript Observales的一部分。ObservaleArray是与RxJS的Observales和Angular不兼容的NativeScript Observales的一部分。
this.arrList.getItem(pos.address
;)在控制台中,我无法读取未定义的属性地址。console.log(“地址”,getValue);您确定传递到函数中的pos
有效吗?ie你确定pos
不大于数组长度吗?我会检查并让你知道。@Nicolaseurdu你的评论this.arrList.getItem(pos).address
写得很好。谢谢你的回答。你能将此作为答案发布吗?this.arrList.getItem(pos.address
;)在控制台中,我无法读取未定义的属性地址。console.log(“地址”,getValue);您确定传递到函数中的pos
有效吗?ie你确定pos
不大于数组长度吗?我会检查并让你知道。@Nicolaseurdu你的评论this.arrList.getItem(pos).address
写得很好。谢谢你的回答。你能把这个贴出来作为答案吗?