使用 JavaScript 将 JSON 响应打印为 PDF 或 Excel
Print JSON response as PDF or Excel using JavaScript
我正在使用 Form.io (http://formio.github.io/formio.js/app/examples/customendpoint.html
// Triggered when they click the submit button.
form.on('submit', function(submission) {
console.log(submission);
alert('Submission sent to custom endpoint. See developer console.');
return fetch('https://hookb.in/ZrRRbJBe', {
body: JSON.stringify(submission),
headers: {
'content-type': 'application/json'
},
method: 'POST',
mode: 'cors',
})
.then(response => {
form.emit('submitDone', submission)
response.json()
})
});
});
并且我在控制台日志中收到 JSON 响应。我正在尝试而不是把它放在控制台日志中,我想把数据放在 PDF 格式中。
我用代码
<div class="entry">
<h1>{{data.page1Text}}</h1>
<div class="body">
{{body}}
</div>
但它仍然以 {{data.page1Text}}
的形式出现,我可以使用任何方式将 JSON 放入 PDF 格式或放入 EXCEL,而不是放入控制台.
要在 PDF 输出中显示表单数据,您需要在表单中使用内容组件,然后您可以使用以下内容打印您的字段数据。
<h1>{{ data.page1Text }}</h1>
我正在使用 Form.io (http://formio.github.io/formio.js/app/examples/customendpoint.html
// Triggered when they click the submit button.
form.on('submit', function(submission) {
console.log(submission);
alert('Submission sent to custom endpoint. See developer console.');
return fetch('https://hookb.in/ZrRRbJBe', {
body: JSON.stringify(submission),
headers: {
'content-type': 'application/json'
},
method: 'POST',
mode: 'cors',
})
.then(response => {
form.emit('submitDone', submission)
response.json()
})
});
});
并且我在控制台日志中收到 JSON 响应。我正在尝试而不是把它放在控制台日志中,我想把数据放在 PDF 格式中。 我用代码
<div class="entry">
<h1>{{data.page1Text}}</h1>
<div class="body">
{{body}}
</div>
但它仍然以 {{data.page1Text}}
的形式出现,我可以使用任何方式将 JSON 放入 PDF 格式或放入 EXCEL,而不是放入控制台.
要在 PDF 输出中显示表单数据,您需要在表单中使用内容组件,然后您可以使用以下内容打印您的字段数据。
<h1>{{ data.page1Text }}</h1>