我找到并使用了Ben Forta's nice tutorial for related selects。在第一个选择中,用户选择一个物种。在第二个选择中填充了化学品清单。第二个选择是多选。
我现在正在尝试使用Chosen jQuery plugin。它在我尝试过的其他选项上运行良好,但是当我尝试使用相关选项时,它无效。有可能绑定的东西吗?
Select Species:
<cfform name="mainform" method="Post" action="organism.cfm">
<cfselect name="SpeciesID" class="chosen-select"
bind="cfc:species.getSpecies()" bindonload="true"></cfselect>
<script type="text/javascript" charset="utf8" src="chosen.jquery.js">
</script>
<script>
$(document).ready(function() {
$('cfselect').chosen()});
</script>
Select a chemical:
<cfselect name="AnalyteID" multiple="yes" required="Yes" size="5"
class="chosen-select" message="Please choose a chemical"
bind="cfc:species.getChemName({SpeciesID})"
</cfselect>
CFC
<cfcomponent output="false">
<cfset THIS.dsn="MyDatabase">
<!--- Get array of species --->
<cffunction name="getSpecies" access="remote" returnType="array">
<!--- Define variables --->
<cfset var data="">
<cfset var result=ArrayNew(2)>
<cfset var i=0>
<!--- Get genus species data --->
<cfquery name="data" datasource="#THIS.dsn#">
SELECT DISTINCT SpeciesID, GenusSpecies
FROM Table1
ORDER BY GenusSpecies
</cfquery>
<!--- Convert results to array --->
<cfloop index="i" from="1" to="#data.RecordCount#">
<cfset result[i][1]=data.SpeciesID[i]>
<cfset result[i][2]=data.GenusSpecies[i]>
</cfloop>
<cfreturn result>
</cffunction>
<!--- Get analyte sorted by genus species --->
<cffunction name="getChemName" access="remote" returnType="array">
<cfargument name="SpeciesID" type="numeric" required="true">
<!--- Define variables --->
<cfset var data="">
<cfset var result=ArrayNew(2)>
<cfset var i=0>
<!--- Get analytes --->
<cfquery name="data" datasource="#THIS.dsn#">
SELECT DISTINCT analyteID, ChemName
FROM Table2
WHERE SpeciesID = #ARGUMENTS.SpeciesID#
ORDER BY ChemName
</cfquery>
<!--- Convert results to array --->
<cfloop index="i" from="1" to="#data.RecordCount#">
<cfset result[i][1]=data.analyteID[i]>
<cfset result[i][2]=data.ChemName[i]>
</cfloop>
<cfreturn result>
</cffunction>
</cfcomponent>
也许另一个插件可以更好地满足我的需求。任何建议都会有所帮助。