[英]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.