简体   繁体   中英

Jsreport shows different result when rendering from client and server

I have a template named A and a test Json stored in server. Using normal setup for jsreport to render PDF work wonder in the server.

Now I want to use Jsreport_client.js to render. I do an AJAX call getJSON to other server and use jsclient to render. 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. Note that the very same JSON render on server correctly

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. 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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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