gpt4 book ai didi

javascript - 如何使用 pdf make 渲染一组复杂对象?

转载 作者:行者123 更新时间:2023-12-03 04:57:58 25 4
gpt4 key购买 nike

我正在尝试将复杂对象数组处理为可读格式 pdfMake 。这是数组:

var areaImpact = [
{
"riskID":"f0bf6fa1-0a6b-e6e3-9ec08bd67751",
"description":"Matt's printing testMatt's printing testMatt's printing test",
"type":"Safety",
"consequences":{
"items":[
"Matt's printing test",
"Matt's printing again"
]
},
"safeguards":{
"items":[
"Matt's printing test",
"Matt's printing test agin!!!"
]
},
"actions":{
"items":[
"Matt's awesome printing test"
]
}
},
{
"riskID":"ffd23fa1-0a6b-e6e3-9ec08bd67751",
"description":"Here's another test",
"type":"Safety",
"consequences":{
"items":[
"Matt's printing test",
"Matt's printing again"
]
},
"safeguards":{
"items":[
"Matt's printing test",
"Matt's printing test agin!!!"
]
},
"actions":{
"items":[
"Matt's awesome printing test"
]
}
}
]

我希望 pdf 看起来像这样: Risk List Concept 。 我很难思考这个问题。我该怎么做?在此先感谢您的帮助。

最佳答案

经过一晚的休息,我终于弄清楚了这个问题。可能不是唯一的方法,也不是最好的方法,但这就是我所做的:

function formatRiskList(riskList){
var printableRisks = [];

riskList.forEach(function(risk){

printableRisks.push({text:'Description', style:'subheader'});
printableRisks.push({text:risk.description});
printableRisks.push({text:'Consequences', style:'subheader'});
printableRisks.push({ul: risk.consequences.items});
printableRisks.push({text:'Safegaurds', style:'subheader'});
printableRisks.push({ul: risk.safeguards.items});
printableRisks.push({text:'Actions', style:'subheader'});
printableRisks.push({ul: risk.actions.items});

});

return printableRisks;

}

//And then, in the docdefinition, I did this:
var dd = {content: [formatRiskList(areaImpact.riskList.items)]};

非常简单。我不知道为什么昨晚我遇到了这个问题。我认为这与我尝试嵌套对象与数组的方式有关。请提供您认为合适的任何反馈。

它给了我 this结果。

关于javascript - 如何使用 pdf make 渲染一组复杂对象?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42356990/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com