簡體   English   中英

如何隱藏JSON對象(angular2)?

[英]How to covert JSON Object (angular2)?

我從服務器得到的響應是這樣的:

  {
    "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)中顯示此數據?

@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":"",
  };

 }

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM