简体   繁体   English

JavaScript在JSReport中无法正常运行

[英]JavaScript not functioning correctly in JSReport

trying to use document.getElementById() in jsreport using the scripts section on the left menu, but it reports back 尝试使用左侧菜单上的脚本部分在jsreport中使用document.getElementById() ,但它会向后报告

Error occured - Error during rendering report: document is not defined 发生错误-呈现报告时出错:未定义文档

What gives? 是什么赋予了? This is simple JavaScript to target a particular ID. 这是针对特定ID的简单JavaScript。

The problem is asynchronous related. 问题是异步相关的。 the document.getElementById must come after the the element you want to target is built. document.getElementById必须位于要定位的元素之后。 So putting the script at the bottom of the page fixes the issue. 因此,将脚本放在页面底部可以解决此问题。

Scripts that are included as part of the report generation request rather than inline with the template do not contain document or any other objects generated by the browser. 作为报告生成请求的一部分而不是与模板内联的脚本不包含文档或浏览器生成的任何其他对象。

If you are trying to use Javascript to modify the document, you are almost certainly doing something wrong. 如果您尝试使用Javascript修改文档,则几乎可以肯定是做错了什么。 It's not meant to generate interactive content, so your template and data should already be fixed by the time you send the request. 这并不是要生成交互式内容,因此您的模板和数据应该在发送请求时就已经固定。 You can probably work around this with require.js, but why would you? 您可能可以使用require.js解决此问题,但是为什么呢? If you are really generating a report, you can do everything ahead of time before you ever request output. 如果您确实在生成报告,则可以在请求输出之前提前进行所有操作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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