用于打印嵌套值的键值管道 [英] Keyvalue pipe using to print nested values
本文介绍了用于打印嵌套值的键值管道的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
这里是我的 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 验证 : true
推荐答案
目前根据您的定义,value key 包含一个字符串数组:["{...}"],因此它的输出不会显示您的内容预期的;相反,它将输出索引值 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屋!
查看全文