自定义资源重定向

有时需要在应用程序代码中在运行时解析对报表定义的引用。 例如,假设您使用服务器端数据库来保存报表模板,并使用需要授权的 API 从客户端加载它们。 在这种情况下,报告引擎无法获取这些模板,它依赖于托管应用程序来提供它们。 在这种情况下,您可以使用自定义资源定位器功能。下面的示例展示了如何使用自定义资源定位器来解析 Angular、React、Vue 和纯 JavaScript 应用程序的子报表。 更多信息可参考帮助文档 资源重定向

<!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8" /> <meta http-equiv="X-UA-Compatible" content="IE=edge" /> <title>ActiveReportsJS sample</title> <meta name="viewport" content="width=device-width, initial-scale=1.0" /> <link href="https://fonts.googleapis.com/css2?family=Montserrat:ital,wght@0,300;0,400;0,500;0,600;0,700;1,400&display=swap" rel="stylesheet" /> <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css" integrity="sha384-JcKb8q3iqJ61gNV9KGb8thSsNjpSL0n8PARn9HuZOnIxN0hoP+VmmDGMN5t9UJ0Z" crossorigin="anonymous" /> <link rel="stylesheet" href="https://cdn.materialdesignicons.com/2.8.94/css/materialdesignicons.min.css" /> <script src="/activereportsjs/demos/arjs/dist/ar-js-core.js"></script> <script src="/activereportsjs/demos/arjs/dist/ar-js-viewer.js"></script> <script src="/activereportsjs/demos/arjs/dist/ar-js-pdf.js"></script> <script src="/activereportsjs/demos/arjs/dist/ar-js-xlsx.js"></script> <script src="/activereportsjs/demos/arjs/dist/ar-js-html.js"></script> <script src="/activereportsjs/demos/arjs-localization/dist/ar-js-locales.js"></script> <script src="$DEMOROOT$/lib/purejs/license.js"></script> <link rel="stylesheet" type="text/css" href="/activereportsjs/demos/arjs/styles/ar-js-ui.css" /> <link rel="stylesheet" type="text/css" href="/activereportsjs/demos/arjs/styles/ar-js-viewer.css" /> <style> #viewer-host { margin: 0 auto; width: 100%; height: 600px; } </style> </head> <body> <div id="viewer-host"></div> <script> const viewer = new ActiveReports.Viewer("#viewer-host", { language: "zh", }); GC.ActiveReports.Core.FontStore.registerFonts( "/activereportsjs/demos/resource/fontsConfig.json" ).then(() => { viewer.open("MainReport", { ResourceLocator: { getResource: (resourceId) => { var reportUrl; switch (resourceId) { case "MainReport": reportUrl = "reports/CarsListing.rdlx-json"; break; case "VehicleDetailsSubreport": reportUrl = "reports/VehicleDetails.rdlx-json"; break; case "ManufacturerDetailsSubreport": reportUrl = "reports/ManufacturerDetails.rdlx-json"; break; default: reportUrl = null; break; } if (reportUrl) return fetch(reportUrl).then((data) => data.json()); }, }, }); }); </script> </body> </html>