【问题标题】:How to covert JSON Object (angular2)?如何转换 JSON 对象(角度 2)?
【发布时间】:2017-11-24 07:08:26
【问题描述】:

我的服务器响应是这样的:

  {
    "message": " list received successfully",
    "success": "true",
    "data": {
    "_list": [{
      "id": "",
      "name": "",
      "image_url": null,
      "is_occupation": true
      },
      {
      "id": "",
      "name": "",
      "image_url": null,
      "is_occupation": true
      }
    ],
    "responseCode":"",
  }

如何在 angular2 的 list(html) 中显示这些数据?

【问题讨论】:

标签: angular


【解决方案1】:
@Component({
selector:'list',
template: `
<table>
    <thead>
        <th>id</th>
        <th>name</th>
        <th>image_url</th>
        <th>is_occupation</th>
    </thead>
    <tbody>
        <tr *ngFor="let data of responseData.data._list">
            <td>{{data.id}}</td>
            <td>{{data.name}}</td>
            <td>{{data.image_url}}</td>
            <td>{{data.is_occupation}}</td>
        </tr>
    </tbody>
</table>`
})
export class List { 

  const responseData={
   "message": " list received successfully",
   "success": "true",
   "data": {
   "_list": [
   {
    "id": "",
    "name": "",
    "image_url": null,
    "is_occupation": true
   },
   {
    "id": "",
    "name": "",
    "image_url": null,
    "is_occupation": true
   }],
   "responseCode":"",
  };

 }

【讨论】:

    猜你喜欢
    • 2021-02-09
    • 2018-04-08
    • 2018-09-09
    • 2020-08-01
    • 1970-01-01
    • 2017-09-25
    • 2016-01-25
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多