这是行不通的。 jsreport模板引擎仅编译和处理html输出,而不是引用的脚本。
不过你可以试试这个方法:
将一个占位符要放在外部脚本的模板内容。比方说,我们希望把内嵌的jQuery
<script>
$$$myScript
</script>
<script>
$(() => {
alert('yes I have jquery inlined')
})
</script>
创建jsreport custom server script其下载您外部脚本,在这种情况下jQuery和替换占位符,其内容
var getReq = require('request').get
function beforeRender(req, res, done) {
getReq('https://code.jquery.com/jquery-3.1.0.min.js', (err, res, body) => {
req.template.content = req.template.content.replace('$$$myScript', body.toString())
done()
})
}
该脚本将模板前运行引擎被执行,因此您现在可以在其中使用模板引擎标签。
playground live demo here
你能共享工程的代码和不工作的代码。这会让你的问题更加用户友好,并可能让你更好的回答! – alexbt