【发布时间】:2017-03-17 17:30:36
【问题描述】:
我使用了以下代码,但脚本代码 beforerender 方法在本地机器上不起作用。有人可以告诉我这个方法不起作用。
在 jsreport studio 上使用把手的 html 代码:
<table>
<tr>
<th>Country</th>
<th>Name</th>
<th>abbrivation</th>
<th>Area</th>
<th>Largest_city</th>
<th>capital</th>
</tr>
{{#each stats.RestResponse.result}}
<tr>
<td>{{country}}</td>
<td>{{name}}</td>
<td>{{abbr}}</td>
<td>{{area}}</td>
<td>{{largest_city}}</td>
<td>{{capital}}</td>
</tr>
{{/each}}
</table>
Script code:
function beforeRender(done) {
require('request')({ url:"http://services.groupkt.com/state/get/IND/all", json:true}, function(err, response, body){
console.log("check-->",JSON.stringify(body));
request.template.content = JSON.stringify(body);
request.data = { stats: body };
done();
});
}
【问题讨论】:
-
不确定是否理解...您是否忘记了一些代码或所有内容都存在?你的车把代码在哪里?此外,如果您想使用车把模板,您应该添加带有脚本标签的声明。
-
这是安装在本地机器上的 jsreport studio。我通过在线为 jsreport studio 运行输出相同的代码,在 jsreport studio 中,脚本 ajax 响应使用把手打印在 html 上,即 {{#each stats.RestResponse.result}} 以 {{/each}} 结尾。那是确切的代码(如果你知道 jsreport studio?)
-
好吧,我不知道这个工具。在线版本是否使用完全相同的代码或运行也有问题?
-
谢谢,在网上没有问题,一切正常。在本地机器上设置 jsreport studio 后我遇到了问题。
-
不客气,很高兴你找到了答案
标签: javascript handlebars.js jsreport