ColdFusion循环通过Struct

时间:2013-11-22 18:30:27

标签: coldfusion cfloop application.cfm

我在Application.cfm中有这些代码:

<CFSET Application.Payroll.Garnishment.PmtCodes = structNew()>
<CFSET Application.Payroll.Garnishment.PmtCodes[1] = "0 - Canceled check">
<CFSET Application.Payroll.Garnishment.PmtCodes[2] = "1 - Closed paymentadjustment">
<CFSET Application.Payroll.Garnishment.PmtCodes[3] = "2 - Multiple payments on one check">
<CFSET Application.Payroll.Garnishment.PmtCodes[4] = "3 - ACH/CTP Payments">
<CFSET Application.Payroll.Garnishment.PmtCodes[5] = "5 - Check Pick-up">
<CFSET Application.Payroll.Garnishment.PmtCodes[6] = "5A - Special Handling">
<CFSET Application.Payroll.Garnishment.PmtCodes[7] = "7 - One invoice paid on one check">
<CFSET Application.Payroll.Garnishment.PmtCodes[8] = "8 - Payroll - Garnishment (Payroll use only)">
<CFSET Application.Payroll.Garnishment.PmtCodes[9] = "9 - Manual check/wire transfer/bankdraft">
<CFSET Application.Payroll.Garnishment.PmtCodes[10] = "C - ACH Transfers (ap use only)">
<CFSET Application.Payroll.Garnishment.PmtCodes[11] = "D - Foreign bank drafts">
<CFSET Application.Payroll.Garnishment.PmtCodes[12] = "H - Hospital Managed Care">
<CFSET Application.Payroll.Garnishment.PmtCodes[13] = "M - Cash advances (AP use only)">
<CFSET Application.Payroll.Garnishment.PmtCodes[14] = "T - Wire US/ Foreign $ to Foreign bank (ap)">
<CFSET Application.Payroll.Garnishment.PmtCodes[15] = "V - Multiple Vendor Payments on credit card">
<CFSET Application.Payroll.Garnishment.PmtCodes[16] = "W - Wire US/Foreign $ US/Foreign bank (ap)">
<CFSET Application.Payroll.Garnishment.PmtCodes[16] = "Y - Payroll rush Checks (ap use only)">
<CFSET Application.Payroll.Garnishment.PmtCodes[16] = "Z - Student Aid check from Banner">

我正在尝试使用struct在update-employee.cfm上创建一个下拉列表,如下所示:

<SELECT NAME="PmtCodes" SIZE="1">    
    <CFOUTPUT>      
    <CFLOOP collection="#Application.Payroll.Garnishment.PmtCodes#" item="key">
       <OPTION VALUE="#Application.Payroll.Garnishment.PmtCodes[key]#">  </OPTION>       
    </CFLOOP>
    </CFOUTPUT>
</SELECT>

但是,下拉列表中没有填充数据。有什么建议?感谢。

2 个答案:

答案 0 :(得分:2)

您需要在<option>代码中显示内容

如果要显示值并返回值

<OPTION VALUE="#Application.Payroll.Garnishment.PmtCodes[key]#">#xmlformat(Application.Payroll.Garnishment.PmtCodes[key])#</OPTION>

如果要返回密钥

<OPTION VALUE="#key#">#xmlformat(Application.Payroll.Garnishment.PmtCodes[key])#</OPTION>

包括xmlformat(),以便如果您的结构具有特殊字符,则不会破坏表单

答案 1 :(得分:0)

我认为您还需要在OPTION标签中包含一些内容。所以我会将该部分写为

<OPTION VALUE="#Application.Payroll.Garnishment.PmtCodes[key]#"> #Application.Payroll.Garnishment.PmtCodes[key]#  </OPTION>