简体   繁体   English

在HTML页面中使用angularjs显示JSON数据

[英]Display json data using angularjs in html page

I have to display name and ownername in html page, data is in JSON format (from MongoDB database) 我必须在html页面中显示名称和所有者名称,数据为JSON格式(来自MongoDB数据库)

While displaying in html, I am getting name correctly but ownername is not displaying properly instead it's displaying the complete object inside owner. 在html中显示时,我可以正确获取名称,但是ownername不能正确显示,而是在owner内部显示完整的对象。

Json: JSON:

/* 1 */
{
    "_id" : ObjectId("550994e21cba9597624195aa"),
    "name" : "Deploy Renderer Code",
    "detail" : "Deploy Renderer code in PROD 1 boxes.",
    "scheduledStartDate" : ISODate("2015-05-12T09:00:00.000Z"),
    "scheduledEndDate" : ISODate("2015-05-12T11:00:00.000Z"),
    "env" : "PROD 1",
    "type" : "Pre Release Activity",
    "team" : {
        "id" : "55097d581cba95976241958d",
        "name" : "Renderer"
    },
    "owners" : [ 
        {
            "ownerName" : {
                "id" : "VENKAT17",
                "name" : "Sundar Venkataraman"
            },
            "ownerTeam" : {
                "id" : "550992951cba9597624195a8",
                "name" : "RETS"
            }
        }
    ],
    "comments" : "Add SPI number, if any.",
    "release" : {
        "id" : "5509904f1cba9597624195a5",
        "name" : "LexisAdvance R5.1"
    },
    "status" : "Assigned"
}

Angular view (html code) 角度视图(html代码)

<div class="row">
  <table class="table table-bordered">
    <thead>
        <tr>
            <th style="text-align: center;">Task name</th>
            <th style="text-align: center;">Owner name</th>
            <th style="text-align: center;">Authorize</th>
        </tr>
    </thead>
        <tbody>
            <tr ng-repeat="task in taskDetails">
                <td style="text-align: center;">{{task.name}}</td>
                <td style="text-align: center;">{{task.owners}}</td>
                <td  style="text-align:center;">
                    <button class="btn btn-mini btn-primary" ng-click="approveTask(taskDetails.indexOf(task), task)">Approve</button>
                    <button class="btn btn-mini btn-danger" ng-click="rejectTask(taskDetails.indexOf(task), task)">Reject</button>
                </td>
            ![enter image description here][1]</tr>

        </tbody>
  </table>

task.owners is a list of objects. task.owners是对象列表。 To get the first owner, you would use: 要获得第一个所有者,您可以使用:

<td style="text-align: center;">{{task.owners[0].ownerName.name}}</td>

Looping through all owners will be better: 遍历所有所有者会更好:

<td style="text-align: center;">
  <span ng-repeat="owner in task.owners">{{owner.ownerName.name}}{{$last ? '' : ', '}}</span>
</td>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM