简体   繁体   English

如何接收从客户端应用程序传递到jsreport服务器的数据

[英]How to receive the data that is being passed from client app to the jsreport server

I am trying to generate a pdf report from my angular app connecting to jsreport. 我正在尝试从连接到jsreport的角度应用程序生成pdf报告。 My client app is doing a POST call by passing a sample data to the report server in this way. 我的客户端应用程序通过以这种方式将示例数据传递到报表服务器来进行POST调用。

 $http.post('http://localhost:5488/api/report', {
      'template': {
        'shortid': 'SypJSv75e',
        "data": {"name": "John Doe"}
      }
    })
    .success(function (response) {
     console.log(response)
    });

As you see in the above code that I am passing {"name": "John Doe"} to the report server. 如您在上面的代码中看到的,我正在将{“ name”:“ John Doe”}传递到报表服务器。

On the report server, this is the code that I have in the custom scripts section. 在报表服务器上,这是我在“自定义脚本”部分中拥有的代码。

function beforeRender(req, res, done) {
req.data.generatedOn = new Date();
done();
}

How do I receive the data in the jsreport that is being passed from client app? 如何从客户端应用传递的jsreport中接收数据?

The data property should not be inside the template and your request should look like this data属性不应位于template ,您的请求应如下所示

$http.post('http://localhost:5488/api/report', {
      template: { shortid: 'SypJSv75e' },
      data: { name: "John Doe"}
    })
    .success(function (response) {
     console.log(response)
    });

Then you can reach "John Doe" inside template content using {{name}} or in custom script as 然后,您可以使用{{name}}或在自定义脚本中访问模板内容内的“ John Doe”

function beforeRender(req, res, done) {
  //prints into debug John Doe
  console.log(req.data.name)
  done();
}

You can later consider using jsreport browser javascript client to invoke rendering calls. 您稍后可以考虑使用jsreport浏览器javascript客户端来调用渲染调用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM