键值管道用于打印嵌套值 [英] Keyvalue pipe using to print nested values

查看:58
本文介绍了键值管道用于打印嵌套值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我的stackblitz https://stackblitz.com/edit/angular-vj4llg

Here my stackblitz https://stackblitz.com/edit/angular-vj4llg

要打印嵌套数组值,我正在使用键值管道

To print nested array values, I am using Keyvalue pipe

<p>Use keyvalue pipe</p>
<ul *ngFor="let stdObj of student">
    <li>ID : {{stdObj.id}} Name : {{stdObj.name}}
        <ng-container *ngFor="let test of stdObj?.value | keyvalue">
            {{test.key}} : {{test.value}}
        </ng-container>
    </li>
</ul>

在打字稿中

 this.student = [
      {
        id:123,
        name: "Test",
        value:["{pass: true,verified: true}"]
      }, 
      {
        id:435,
        name:"Test12",
        value:["{pass: false, verified: true}"]
      }
    ]

期望输出为

ID : 123 Name : Test pass : true verified : true

推荐答案

当前,根据您的定义,值键包含一个字符串数组:["{...}"],因此该输出不会显示您的内容预期的;相反,它将输出索引值0作为第一项的键"值,而将"{...}"作为其值.

Currently by your definition, value key holds an array of string: ["{...}"], so the output for it will not show what you expected; instead, it will output index value 0 as 'key' value for the first item, while "{...}' as its value.

因此,为了获得您期望的结果,请重新定义值,如下所示:

So in order to get what you expected, re-defined value as below:

value: {pass: true,verified: true}

这篇关于键值管道用于打印嵌套值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆