【问题标题】:Bind JSON object array to View in Angular2 nativescript将 JSON 对象数组绑定到 Angular2 nativescript 中的视图
【发布时间】:2016-12-26 16:30:53
【问题描述】:

我有一个像这样从我的 API 返回的 JSON 对象

{
"ID": "GM5VY",
"Passengers": [
 {
"Firstname": "TEST",
"Lastname": "TRAVELLER",
"TotalCount": "1",
FqtT": [
  {
    "MembershipID": "XXXXXX"
  }
],
"Errors": null,
"Information": null,
"Warnings": null
}
],
"Errors": null,
"Information": null,
"Warnings": null
}

我正在使用管道过滤器将此对象转换为数组,并尝试在视图中显示乘客的名字。但我无法检索

<StackLayout *ngFor=" let passengerls of PassengerDetails | objtoarray; let i = index">
    <Label [text]="passengerls?.value?.Passengers ? passengerls?.value?.Passengers[i].Firstname:null"> </Label>                        

</StackLayout>

请帮助我实现这一目标!!!

【问题讨论】:

  • 显示你的管道实现?
  • 你能设置一个示例 plunkr

标签: angular nativescript


【解决方案1】:

如何使用更简单的方法来迭代数组:

<StackLayout *ngFor="let passenger of PassengerDetails.Passengers">
  <Label [text]="passenger.Firstname"></Label>
</StackLayout>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2017-04-12
    • 2019-08-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-01-08
    • 1970-01-01
    相关资源
    最近更新 更多