简体   繁体   中英

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

Error occured - Error during rendering report: document is not defined

What gives? This is simple JavaScript to target a particular ID.

The problem is asynchronous related. the document.getElementById must come after the the element you want to target is built. 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. 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? If you are really generating a report, you can do everything ahead of time before you ever request output.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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