简体   繁体   English

从客户端和服务器渲染时,Jsreport显示不同的结果

[英]Jsreport shows different result when rendering from client and server

I have a template named A and a test Json stored in server. 我有一个名为A的模板,一个测试Json存储在服务器中。 Using normal setup for jsreport to render PDF work wonder in the server. 使用jsreport的常规设置来呈现PDF在服务器中的工作奇迹。

Now I want to use Jsreport_client.js to render. 现在,我想使用Jsreport_client.js进行渲染。 I do an AJAX call getJSON to other server and use jsclient to render. 我对其他服务器执行AJAX调用getJSON并使用jsclient进行渲染。 But now the data is not sent/processed correctly. 但是现在数据无法正确发送/处理。 The key located near the root of JSON object is correct but the rest is not. 位于JSON对象根附近的密钥是正确的,而其余的则不是。 Note that the very same JSON render on server correctly 请注意,相同的JSON可以正确在服务器上呈现

EDIT: Below is the call 编辑:下面是电话

$.getJSON(AJAXurl).success(function (people) {
 jsreport.serverUrl = 'http://localhost:5488';
 var request = {
   template: { 
     shortid:"rJPUhdmv"
   },
   data: people
  };                                   
  jsreport.render('_blank', request);
})

Below is the returned request structure 以下是返回的请求结构

{
  "responseHeader":{
    "status":0,
    "params":{
      "fq":"{!frange l=0.80 }query($q)",
      "q":"{!percentage}etco~",
      "group.field":"ent_id"
}},

  "grouped":{
    "ent_id":{
      "ngroups":3,
      "groups":[{
          "groupValue":"214493",
          "doclist":{"numFound":1,"docs":[
              {

                "add_city":"London",
                "add_street":"Devonshire Street",
                "nam_comp_name":"ETCO INTERNATIONAL COMMODITIES LTD.",
                "add_country":"GB",             
                "add_id":"668638",
                "score":1.0}]
          }},OTHER GROUP.....]}}},

  "highlighting":{
    "C":{
      "nam_comp_name":["<span class=\"highlight\">ETO</span>"]}
}}

And below is the handler in server 下面是服务器中的处理程序

// Can not read any parameters
 </thead>
          {{#each grouped.ent_id.groups}}
          </tr>
          <td>{{offsetIndex @index}}</td>
          {{#each doclist.docs}}
          <td>{{this.nam_comp_name}}</td>
          <td>{{convertScore this.score}}</td>
           <td>{{this.add_country}} {{this.add_city}} {{this.add_street}}</td>
            <td>{{lis_name}}</td>
          {{/each}}                   
          </tr>
           {{/each}}

Another handler which has both correct and incorrect/unreadable data 另一个具有正确和不正确/不可读数据的处理程序

 {{#responseHeader.params}}
  <tr>
    <th>Search term</th>
    <td>{{sanitizeQuery this.q}}</td>    // Read correctly
  </tr>
  <tr>
    <th>Sanction List: </th>
    <td>{{sanitizeQuery this.fq.[0]}}</td> // Incorrectly
  </tr>
  <tr>
    <th>Countries:</th>
    <td>{{sanitizeQuery this.fq.[1]}}</td> // Incorrectly
  </tr>
   {{/responseHeader.params}}
    <tr>
    <th>Search by:</th>
    <td>"Method of searching"</td> // Incorrectly
   </tr>
    <tr>
    <th>Found total:</th>
    <td>{{grouped.ent_id.ngroups}}</td> // Read correctly

Helpers 帮手

function offsetIndex(index) {
    return index+1;
}

function convertScore(score) {
    a = parseFloat(score);
    return a*100;
}
function sanitizeQuery(query) {
    a =query
        .replace(/{+.*?}+/g, "")
        .replace(/\[\[|\]\]/g, "")
        .replace(/<.*?>/g, "")
        .replace(/add_country:/,"")
        .replace(/program_number:/,"")
        .replace(/~/,"");
    return a;
}

This was a bug with array serialization in jsreport browser client. 这是jsreport浏览器客户端中的数组序列化错误。 Now it is fixed. 现在已修复。

Please update to jsreport-browser-client-dist@1.0.2 or update whole jsreport where you can also find it in jsreport@1.0.9 请更新到jsreport-browser-client-dist@1.0.2或更新整个jsreport,您也可以在jsreport@1.0.9中找到它。

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

相关问题 如何接收从客户端应用程序传递到jsreport服务器的数据 - How to receive the data that is being passed from client app to the jsreport server 结果到达客户端时,Next JS 服务器端渲染如何工作? - How does Next JS server side rendering works when result hits client? 服务器端渲染生成的标记与客户端渲染不同 - Server side rendering generating different markup than client side rendering 骨干网将客户端渲染与服务器端渲染区分开 - Backbone differentiate client side rendering from server side rendering 我正在尝试将pdf文件从节点服务器下载到React Client,但是当我打开它时,它显示为空白 - I'm trying to download a pdf file from a node server to a react client but when I open it, it shows blank SvelteKit 渲染随机道具在服务器和客户端之间是不同的 - SvelteKit Rendering a Random Prop is different between server and client 为什么使用断点时chrome的渲染结果不一样? - Why chrome's rendering result is different when using breakpoints? 在服务器和客户端上渲染时应该如何处理日期字符串? - How should date strings be handled when rendering on both server and client? TaskCanceledException:呈现jsreport时取消了任务 - TaskCanceledException: a task was cancelled while rendering jsreport React JS:从服务器渲染迁移到纯客户端 - React JS : Migrate from server rendering to pure client side
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM