background image
Web 报表工具 FineReport 的 JS API 开发(一) 
很多报表软件可以利用 JS 接口来实现更多更复杂的功能。以 FineReport 为例,开放了大量
的 JS API 给用户,根据执行 JS 的主体不同可以将分为三大类:FR、FS 和 contentWindow。 
在 js 语句中执行可以使用 FR 的方法或者属性,比如说 FR.Msg.alert,FR 中的方法比如引入
finereport.js。FS 的方法可以用于数据决策系统中的 js 接口,比如说 FS.tabPane.addItem。而
contentWindow 是在 web 页面集成的时候,将 F 报表嵌入在 iframe 中,调用报表对象时使
用 的 接 口 , 比 如 说 : document.getElementById('reportFrame').contentWindow , 其 中
document.getElementById('reportFrame')是获取 iframe 对象,contentWindow 是报表对象,相
当于 html 中的 window 对象。 
由于篇幅,这里先介绍 FR 
FR 
大家知道,预览报表时,报表 servlet 会将 cpt 模板转为 html,在这个 html 的 head 头部中
会引入 FR 的 js,如下: 
<script type="text/javascript" 
src="/WebReport/ReportServer?op=emb&resource=finereport.js"></script> 
这个 finereport.js 中包含了许多内置的 function 以及一些公有的属性,不管在模板中还是其
他网页中,只要引入了 finereport.js,就能够通过 FR.xxx 的形式调用公有的属性与方法 
比如,在模板中使用,访问模板时会自动引入 finereport.js,因此在模板的 js 脚本中可以直
接使用 FR.xxx 来调用方法,如下图: 
 
或者需要在自己的网页如某个 jsp 页面中调用 FR 的方法,要先引入 finereport.js,再通过
FR.xxx 来调用,如下: 
<html> 
  <head> 
    <script type="text/javascript" 
src="/WebReport/ReportServer?op=emb&resource=finereport.js"></script> 
    <script type="text/javascript"> 
 
var url = FR.cjkEncode("/WebReport/ReportServer?reportlet=Gettingstarted.cpt&地区=华
东"); 
 
window.open(url); 
    </script> 
  </head>