回 帖 发 新 帖 刷新版面

主题:[原创]使用FineReport报表软件时参数控件取值与置数


    在[url=http://www.finereport.com/cn/knowledge.html]报表[/url]参数中,可通过添加参数控件的编辑后事件来实现用一个参数控制另一个参数。以下例子是用参数username来对state置数,username为下拉框自定义的几个名字,state为单选按钮,1和2。当username有值时,取state的状态,要是2,则置为1,若为1,则不变;当没有值时,取state的状态,要是2,则不变,若为1,则置为2。
1.    连接数据库FRDemo
2.    设计模板
2.1    新建[url=http://www.finereport.com/cn/knowledge.html]报表[/url]
2.2    定义参数
在菜单栏中选择[url=http://www.finereport.com/cn/knowledge.html]报表[/url]|报表参数,打开参数定义面板,添加两个参数state和username,默认值选择字符串形式,如下图 
[img]http://www.finereport.com/forumimages/e101.png[/img] 
2.3    参数设计
打开参数设计界面,按照下图安排参数的位置
 
[img]http://www.finereport.com/forumimages/e102.png[/img]
    state控件类型选择单选按钮组,数据为自定义的1和2,如图
 
[img]http://www.finereport.com/forumimages/e103.png[/img]
    username控件类型为下拉框,数据也为自定义的几个数据,如图
 
[img]http://www.finereport.com/forumimages/e104.png[/img]
2.4    事件编辑
在username的事件编辑中添加编辑后事件,JS代码如下
var state= this.options.form.getWidgetByName("state");
var username = this.options.form.getWidgetByName("username").getValue();
if (!username){
    state.setValue(2);
}else{
    state.setValue(1);
}
该段代码是用来对state参数置数,当username为空时,将state置数为2,当username有值时,将state置数为1,如图所示
 
[img]http://www.finereport.com/forumimages/e105.png[/img]
3.    保存并预览
点击设计器分页预览,当username有值是,state置数为1
 
[img]http://www.finereport.com/forumimages/e106.png[/img]
当username为空时,state置数为2
 
[img]http://www.finereport.com/forumimages/e107.png[/img]
    注意,state无法通过username置数为,Js里面,state为0,默认返回false
    以上例子是获得控件的实际值。
    通过该控件取该控件的显示值方法是arguments[0],
通过该控件取另一个控件的值方法是
    this.options.form.getWidgetByName(“所要获得显示值的控件名”).options.items    [i].text
    另外,一个控件无法对另一个控件的显示值置数。

回复列表 (共2个回复)

沙发

范俊辉(软件)已帮助过4385人已回答了5594个问题

板凳

变量在report++中不是用?来表示的,要用#,例子中写得很明白的,自己看看吧。

我来回复

您尚未登录,请登录后再回复。点此登录或注册