你好,我想从下面的查询中打印最里面的内容,如何访问计划>个人>标题,并在屏幕上打印内容。
非常感谢!
我从data.js获得数据,如下所示:
export default [
{
sys: {
id: "1"
},
fields: {
name: "cloud hosting",
slug: "cloud-hosting",
type: "hosting",
price: 100,
size: 200,
capacity: 1,
featured: true,
description:
"The power of SSD + Simplicity of cPanel",
extras: [
"Plush pillows and breathable bed linens",
"Soft, oversized bath towels",
"Full-sized, pH-balanced toiletries",
"Complimentary refreshments",
"Adequate safety/security",
"Internet",
"Comfortable beds"
],
plans:[
{
fields:{
personal:{
title: "personal"
}
}
}
]
}
}
];发布于 2020-05-17 06:40:10
您可以使用flatMap。我假设你的数据是一个数组。
var data = [{ sys: { id: "1" }, fields: { name: "cloud hosting", slug: "cloud-hosting", type: "hosting", price: 100, size: 200, capacity: 1, featured: true, description: "The power of SSD + Simplicity of cPanel", extras: [ "Plush pillows and breathable bed linens", "Soft, oversized bath towels", "Full-sized, pH-balanced toiletries", "Complimentary refreshments", "Adequate safety/security", "Internet", "Comfortable beds" ], plans: [{ fields: { personal: { title: "personal" } } }] }}];
result = data.flatMap(({fields})=>fields.plans.map(k=>(k.fields.personal.title)));
console.log(result);
https://stackoverflow.com/questions/61847871
复制相似问题