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

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

我正在尝试从连接到 jsreport 的 angular 应用生成 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 browser javascript client 调用渲染调用。