[英]Jsreport shows different result when rendering from client and server
[英]How to receive the data that is being passed from client app to the jsreport server
我正在尝试从连接到jsreport的角度应用程序生成pdf报告。 我的客户端应用程序通过以这种方式将示例数据传递到报表服务器来进行POST调用。
$http.post('http://localhost:5488/api/report', {
'template': {
'shortid': 'SypJSv75e',
"data": {"name": "John Doe"}
}
})
.success(function (response) {
console.log(response)
});
如您在上面的代码中看到的,我正在将{“ name”:“ John Doe”}传递到报表服务器。
在报表服务器上,这是我在“自定义脚本”部分中拥有的代码。
function beforeRender(req, res, done) {
req.data.generatedOn = new Date();
done();
}
如何从客户端应用传递的jsreport中接收数据?
data
属性不应位于template
,您的请求应如下所示
$http.post('http://localhost:5488/api/report', {
template: { shortid: 'SypJSv75e' },
data: { name: "John Doe"}
})
.success(function (response) {
console.log(response)
});
然后,您可以使用{{name}}
或在自定义脚本中访问模板内容内的“ John Doe”
function beforeRender(req, res, done) {
//prints into debug John Doe
console.log(req.data.name)
done();
}
您稍后可以考虑使用jsreport浏览器javascript客户端来调用渲染调用。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.