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

Jsreport shows different result when rendering from client and server

本文关键字:显示 结果 客户端 服务器 Jsreport      更新时间:2023-09-26

我有一个名为a的模板和一个存储在服务器中的测试Json。使用jsreport的正常设置来渲染服务器中的PDF工作奇迹。

现在我想使用Jsreport_client.js进行渲染。我对其他服务器进行AJAX调用getJSON,并使用jsclient进行渲染。但现在数据没有正确发送/处理。位于JSON对象根附近的键是正确的,但其他键则不正确。请注意,服务器上完全相同的JSON呈现正确

编辑:下面是呼叫

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

以下是返回的请求结构

{
  "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>"]}
}}

下面是服务器中的处理程序

// 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}}

具有正确和不正确/不可读数据的另一个处理程序

 {{#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

帮助

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;
}

这是jsreport浏览器客户端中数组序列化的一个错误。现在它已修复。

请更新到jsreport-browser-client-dist@1.0.2或者更新整个jsreport,您也可以在jsreport@1.0.9