在Angular项目中,在一个具有顶部和侧面标题的表中显示两个级别的json键值对



我正试图在一个表中拥有以下键值对。Angular平台中需要该表,因此将使用*ngFor循环。我正在寻找一种没有变通方法的有效方法,比如创建2个表并连接它们。

{"Lawrence":{"Unallocated":215,"All":2,"Both":0,"Slabs":3,"Tiles":121},"West":{"Unallocated":82,"All":1,"Both":0,"Slabs":1,"Tiles":1},"King":{"Unallocated":388,"All":15,"Both":12,"Slabs":264,"Tiles":558}}

我想要一张像这样的桌子

LawrenceWestKing

const data=JSON.parse(`{"Lawrence":{"Unallocated":215,"All":2,"Both":0,"Slabs":3,"Tiles":121},"West":{"Unallocated":82,"All":1,"Both":0,"Slabs":1,"Tiles":1},"King":{"Unallocated":388,"All":15,"Both":12,"Slabs":264,"Tiles":558}}`)
const newData=Object.entries(data).map(([key,value])=>{
const y={['title']:key}
return Object.assign({},y,value)
})
const headers=Object.keys(newData[0])
console.log(headers)
console.log(JSON.stringify(newData,null,4))
.as-console-wrapper { max-height: 100% !important; top: 0; }

最新更新