以角度嵌套对象的循环

问题描述 投票:0回答:1

我想遍历嵌套对象。

"movieRating": {
"rate": [{ 
    "rating9": 9,
    "count9": 158
}, {
    "rating8": 8,
    "count8": 101
}, {
    "rating7": 7,
    "count7": 32
}, {
    "rating6": 6,
    "count6": 48
}, {
    "rating5": 5,
    "count5": 125
}],
"totalCount": 456}

这是我的HTML文件

<div *ngFor="let movie of movies" class="container">
    <table   class="table">
        <tbody>
            <tr >
                <th><img src="#"></th>
                <td >{{movie.movieRating.rating9}}</td>
            </tr>
        </tbody>
   </table>
</div>    

如果我尝试{{movie.movieRating.rating9}},则无法正常工作。但是{{movie.movieRating.totalCount}}有效。有没有办法获取rating9count9

javascript node.js angular typescript ngfor
1个回答
1
投票

[Rating9位于比率数组的位置0,因此可以使用{{movie.movieRating.rate[0].rating9}}进行访问。

<div *ngFor="let movie of movies" class="container">
    <table   class="table">
        <tbody>
            <tr >
                <th><img src="#"></th>
                <td >{{movie.movieRating.rate[0].rating9}}</td>
            </tr>
        </tbody>
   </table>
</div>   
© www.soinside.com 2019 - 2024. All rights reserved.