将键值映射到数据中的其他值 [英] Map a key value to the other values in the data
本文介绍了将键值映射到数据中的其他值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
假设我有以下格式的数据作为json
Suppose I have data coming as json in the below format
[
{
"clauseId": 1,
"clauseName": "cover",
"texts": [
{
"textId": 1,
"text": "hello"
}
]
},
{
"clauseId": 3,
"clauseName": "xyz",
"texts": [
{
"textId": 3,
"text": "hello Everyone"
},
{
"textId": 4,
"text": "Some data"
}
]
}
{
"clauseId": 2,
"clauseName": "joining",
"texts": [
{
"textId": 3,
"text": "hello1"
},
{
"textId": 4,
"text": "hello2"
}
]
}
]
我已经从子句名称中列出了一个列表,例如
I have made a list from clause Name like
c=[joining,xyz]
我想列出文本的来源
d=[hello Everyone,Some data,hello1,hello2]
请提出一些建议
推荐答案
尝试如下:
Working Demo
result = [];
constructor() {
let texts:any[] = this.data.filter(item => this.c.includes(item.clauseName)).sort((a, b) => a.clauseId - b.clauseId).flatMap(x => x.texts);
this.result = texts.map(x => x.text);
}
这篇关于将键值映射到数据中的其他值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文