我目前正在从事一个 ColdFusion (CF) 项目,为我们的员工感谢奖网络应用程序添加功能。
我遇到的问题是如何在返回选择它的网页时保留 cfselect 值。
目前,nomination.cfm 使用子部门名称填充 #1 下拉菜单,并且从 nomination.cfc cffunction getDept 调用。一旦选择了“部门”,则将其作为 cfargument 传递给 nomination.cfc cffunction getEmp。
1. Select the location where your nominee works:
<cfselect name="department" bind="cfc:nominee.getDept ()" bindonload="true" />
2. Select the nominee from the list below
<cfselect name="employee" bind="cfc:nominee.getEmp ({department})" />
所有这些代码都在一个 cfform 中,并在其中提交给 summary.cfm。在summary.cfm 中有一个编辑按钮可以返回到nomination.cfm。我用了
<input type="button" value=" Edit " onclick="history.go(-1);">
但#1 和#2 没有保留其选定的值,而是默认为原始下拉菜单列表。我在文档中读到 cfc 绑定不能“选择”,所以我很茫然。在此先感谢您的帮助!!
以下是nomination.cfc 代码:
<!--- Get array of media types --->
<cffunction name="getDept" access="remote" returnType="array">
<!--- Define variables --->
<cfset var data="">
<cfset var result=ArrayNew(2)>
<cfset var i=0>
<!--- Get data --->
<cfquery name="data" datasource="HatsOff">
SELECT account_number, account_title
FROM departments
<cfif session.vdept is not "All" and session.vdept is not "Letter">
WHERE [departmentname] = '#session.vdept#'
</cfif>
ORDER BY account_title
</cfquery>
<!--- Convert results to array --->
<cfloop index="i" from="1" to="#data.RecordCount#">
<cfset result[i][1]=data.account_number[i]>
<cfset result[i][2]=data.account_title[i]>
</cfloop>
<!--- And return it --->
<cfreturn result>
</cffunction>
<!--- Get art by media type --->
<cffunction name="getEmp" access="remote" returnType="array">
<cfargument name="department" type="string" required="true">
<!--- Define variables --->
<cfset var data="">
<cfset var result=ArrayNew(2)>
<cfset var i=0>
<!--- Get data --->
<cfquery name="data" datasource="HatsOff">
SELECT emp_id, emp_full_name
FROM employees
WHERE account_number = '#ARGUMENTS.department#'
ORDER BY emp_full_name
</cfquery>
<!--- Convert results to array --->
<cfloop index="i" from="1" to="#data.RecordCount#">
<cfset result[i][1]=data.emp_id[i]>
<cfset result[i][2]=data.emp_full_name[i]>
</cfloop>
<!--- And return it --->
<cfreturn result>
</cffunction>
</cfcomponent>