【发布时间】:2019-12-05 02:30:35
【问题描述】:
考虑以下示例:https://playground.jsreport.net/w/anon/VkLWfMyMb-7
我能够使用 jsreports-online 重新创建它。如何将本地化添加到 jsreport-core?
app.get('/test', (req, res) => {
jsreport().init().then((reporter: Reporter) => {
const templatePath: string = path.join(__dirname, 'assets', 'template.html');
const template: string = fs.readFileSync(templatePath, 'utf8');
const exampledatapath: string = path.join(__dirname, 'assets', 'exampledata.json');
const exampledata: string = fs.readFileSync(exampledatapath, 'utf8');
let data = JSON.parse(exampledata);
reporter.render({
template: {
content: template,
engine: 'handlebars',
recipe: 'chrome-pdf',
},
data: data
}).then(function (out: any) {
out.stream.pipe(res);
})
.catch(function (e: any) {
res.end(e.message);
});
}).catch(function (e: any) {
res.end(e.message);
});
});
我能想到的最好的就是这样的data['$localizedResource'] = {key1: 'value1'};
有更好的或内置的方法吗?
【问题讨论】:
标签: jsreport