如何在 angular 6 中使用 ngFor 循环 JSON 对象

循环从 json 对象获取的对象列表


这是我得到的 json 对象


 {

  "0": {

    "0": null,

    "1": "Consolidated Statements of Changes in Stockholders\u2019 Deficit",

    "2": null,

    "3": "",

    "4": "",

    "5": "",

    "6": "Balance at September 30, 2013",

    "7": "",

    "8": "Common stock issued for exercise of options",

    "9": "Common stock issued for services",

    "10": "Common stock issued to employees",

    "11": "Common stock returned by employees",

    "12": "Net loss for the nine months",

    "13": "Shares issued as finance fee",

    "14": "Amortization of deferred compensation",

    "15": "Common stock issued for acquisition",

    "16": "Payment on convertible note",

    "17": "Exercise of common stock warrants",

    "18": "Unrealized loss on securities, net",

    "19": "Preferred stock",

    "20": "Balance at June 30, 2014",

    "21": "",

    "22": "Net loss for the year",

    "23": "Amortization of deferred compensation",

    "24": "Shares issued for conversion of notes payable",

    "25": "Write-off of derivative liability upon conversion",

    "26": "Unrealized loss on securities, net",

    "27": "Retirement of shares",

    "28": "Conversion of Series AA convertible preferred stock",

    "29": "Balance at June 30, 2015"

  },


SMILET
浏览 209回答 2
2回答

慕森卡

您在对象中有对象,因此需要如下运行 for 循环两次。&nbsp;<div *ngFor="let items of testObject | keyvalue">&nbsp; &nbsp; Key: <b>{{items.key}}</b>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;<div *ngFor="let item of items | key">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;value:<b>{{item.value}}</b>&nbsp; &nbsp; &nbsp; &nbsp;</div>&nbsp; &nbsp;<hr>&nbsp;</div>
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

JavaScript