0
我的应用程序需要使用自定义查询中的选项填充html选择。我试图将逻辑放入一个通用的自定义标签中,以便我的视图更清晰,更具可读性。我是cfml新手。使用自定义标签填充<SELECT>?
这里是我的代码:
<!--- ```````````````````````````````````````````````````````````````````````````` --->
<!--- This tag will populate any SELECT with the OPTIONs pulled from the database. --->
<!--- The attributes of this tag are --->
<!--- data_source: The datasource for the query --->
<!--- table_source: The table used for the query --->
<!--- option_value_source: The DB cell to use for the value of the option. --->
<!--- option_inner_source: The DB cell to use for the value of the inner text. --->
<!--- ____________________________________________________________________________ --->
<cfquery name="option_query" datasource="#Attributes.data_source#">
SELECT * FROM #Attributes.table_source#
</cfquery>
<cfoutput query="option_query">
<option value="#Attributes.option_value_source#"> <!--- The cell to be used for the value of the option --->
#Attributes.option_inner_source# <!--- The cell to be used for the inner text of the option --->
</option>
</cfoutput>
我打电话说有:
<label>
Class Name
<select name="className" id="className">
<cf_getOptions data_source="codify" table_source="classes" option_value_source="classes.id" option_inner_source="classes.name">
</select>
</label>
结果是我得到填充了每个结果的词class.name一个SELECT。
什么是最cfm的方式来做到这一点(我认为人们通常不会使用自定义标签)?是否有可能重写此代码以获得正确的结果?
这正是我需要的!谢谢。我想这应该是可能的,只是无法弄清楚如何到达那里。干杯。 – ialexander 2014-12-07 14:57:03