gpt4 book ai didi

drop-down-menu - ColdFusion 中的动态依赖/三重相关选择,第三个不持有第一个选择

转载 作者:行者123 更新时间:2023-12-04 06:38:44 25 4
gpt4 key购买 nike

首先,我不仅是 SO 的新手,而且我也是任何一种网络编程的新手,所以我是新手,感谢您的帮助和耐心等待!因此,以前对 HTML、ColdFusion、SQL、SQL Server 等的经验为零,所以我在过去两周内学到的任何东西。

我正在尝试在 ColdFusion 中制作 3 个动态相关下拉菜单(三重相关选择),最终会在另一个 .CFM 页面中打开 map 。下拉列表是从 SQL Server 中的一个表中填充的。我已经做了很多研究(关于 SO 和其他地方)并且我有一个主要有效的方法,但它有一个问题,我很乐意帮助找出为什么一件事不起作用。我正在使用 .CFC 查询数据库以获取每个下拉菜单的信息,我试图让每个下拉菜单都依赖于前一个,然后在 .CFM 中我使用“绑定(bind)”。这是我的 CFC 和 CFM 代码:

CFC(名为 GettingData):

<cfcomponent displayname="GetStuff" hint="Getting data on cruises from database">
<!---GET ARRAY OF TRIBUTARIES--->
<cffunction name="getData" access="remote" returntype="query" hint="Get data for first select">
<!---define variables--->
<cfset var data="tributary">
<!---Run the query for tributaries--->
<cfquery name="data" datasource="mydatasource">
SELECT distinct Tributary
FROM df_cruises
ORDER BY Tributary
</cfquery>
<!---and return it--->
<cfreturn data>
</cffunction>
<!---Get DATES by tributary--->
<cffunction name="getDates" access="remote" returntype="query"
hint="Get cruise dates by tributary for select dropdown">
<cfargument name="Tributary" type="any" required="no">
<!---Define variables--->
<cfset var data="CruiseDate">
<!---Run query to get Date Data--->
<cfquery name="data" datasource="mydatasource">
SELECT *, CruiseDate AS date <!---this gets date to display correctly in dropdown--->
FROM df_cruises
WHERE Tributary='#ARGUMENTS.Tributary#'<!---single quotes for SQL Server--->
ORDER BY CruiseDate desc
</cfquery>
<!---And return it--->
<cfreturn data>
</cffunction>
<!---getting the html file based on the cruisedate selection--->
<cffunction name="getmapname" access="remote" returntype="query"
hint="Get html file by tributary and cruisedate for dropdown select">
<cfargument name="Tributary" type="any" required="no">
<cfargument name="mapfile" type="any" required="no">
<!---Define variables--->
<cfset var data="">
<cfset var data="">
<!---Get file html Data--->
<cfquery name="data" datasource="mydatasource">
SELECT CruiseDate, Tributary, File_html
FROM df_cruises
WHERE CruiseDate='#ARGUMENTS.mapfile#'AND Tributary='#ARGUMENTS.Tributary#'AND File_html<>'notsampled'
</cfquery>
<!---And return it--->
<cfreturn data>
</cffunction>
</cfcomponent>

CFM(名为 DropdownDisplay):

<cfparam name="url.File_html" default = '2'>
<cfform name="CruiseChoose" action="mapdisplayv3.cfm" method="post">
<table align="center" bgcolor="orange">
<tr>
<th colspan="2">
<font size="+1">First Select a Water Body, Then Choose Cruise Date</font>
</th>
</tr>
<tr>
<td>
<br/>
Tributary/Water Body:<br />
<cfselect name="Tributary"
bind="cfc:GettingData.getData()"
display="Tributary"
value="Tributary"
bindonload="true"
multiple="no"
size="6" />
</td>
<td>
<br />
Cruise Dates:<br />
<cfselect name="CruiseDate"
bind="cfc:GettingData.getDates({Tributary})"
bindonload="false"
type="link"
display="date"
value="CruiseDate"
multiple="no"
size="6"/>
</td>
<td>
<br>
Map Links:<br />
<cfselect name="link"
bind="cfc:GettingData.getmapname({CruiseDate},{Tributary})"
bindonload="false"
type="any"
display="File_html"
value="File_html"
multiple="no"
size="3"/>
</td>
</tr>
<tr>
<td colspan="2" align="center">
<br />
</form>
<!--- submit button --->
<cfoutput> <input type="submit" name="submit" value="View Selected Maps" alt="View Map Selection Button"><br></cfoutput>
<!--- Reset button. --->
<input name="reset" type="reset" value="Clear Selections" alt="Clear Selections Button">
</td>
</tr>
</table>
</cfform>
</html>

The first dropdown is pulling a list of tributaries, and when a ‘Tributary’ is chosen the second dropdown correctly populates the list of ‘CruiseDates’ when they were sampled.第三个下拉菜单应该填充表格中的“File_html”,该表格成为打开另一个 CFM 上数据图像映射的链接。 (这不是我的最终目标,这是我一步步实现的目标。)

The issue I am having is that the third dropdown does not seem to be holding the dependency to the first dropdown selection (Tributary), so when a CruiseDate is selected where 2 tributaries happened to be sampled on the same date both of those File_html 名称显示在第三个下拉列表中(屏幕截图):在 CFC 中,在“getmapname”函数中,我尝试使用 2 个参数(我在网上看到的某个地方使用过)以便我可以重用该参数(连同 cfargument name="mapfile"),以便在最后一个查询中我可以执行以下操作:

<cfquery name="data" datasource="mydatasource">
SELECT CruiseDate, Tributary, File_html
FROM df_cruises
WHERE CruiseDate='#ARGUMENTS.mapfile#' AND Tributary='#ARGUMENTS.Tributary#'
AND File_html<>'notsampled'
</cfquery>

这没有用。当我有 2 个参数时出现错误,它似乎只允许 1 个。

这是第三个下拉列表的屏幕截图,显示虽然选择了“Back River”,但它正在拉取在同一日期采样的 2 个支流的 File_html: screenshot of 3rd dropdown not holding 1st dropdown select

我也开始研究一个 javascript 版本,但我也坚持使用它,因为这已经很接近了,所以我一直在研究这个方法。但是,如果无法使用此方法进行三重相关选择,我将不得不继续!

任何帮助都会非常好,谢谢! -B(很抱歉发了这么长的帖子,只是想说的很透彻)

最佳答案

感谢大家的帮助和耐心,我得到了 2 个参数,第三个下拉菜单现在只返回它应该返回的数据(即,它正确地绑定(bind)到第一个和第二个下拉菜单中的选择)。谢谢你!这是有效的新代码:

氟氯化碳:

<cfcomponent displayname="GetStuff" hint="Getting data on cruises from database">
<!---GET ARRAY OF TRIBUTARIES--->
<cffunction name="getData" access="remote" returntype="query" hint="Get data for first select">
<!---define variables--->
<cfset var data="tributary">
<!---Run the query for tributaries--->
<cfquery name="data" datasource="mydatasource">
SELECT distinct Tributary
FROM df_cruises
ORDER BY Tributary
</cfquery>
<!---and return it--->
<cfreturn data>
</cffunction>
<!---Get DATES by tributary--->
<cffunction name="getDates" access="remote" returntype="query" >
<cfargument name="Tributary" type="any" required="no">
<!---Define variables--->
<cfset var data="CruiseDate">
<!---Run query to get Date Data--->
<cfquery name="data" datasource="mydatasource">
SELECT *, CruiseDate AS date
FROM df_cruises
WHERE Tributary=
<cfqueryparam cfsqltype='cf_sql_varchar' value='#ARGUMENTS.Tributary#'>
ORDER BY CruiseDate desc
</cfquery>
<!---And return it--->
<cfreturn data>
</cffunction>
<!---getting the html file based on the CruiseDate selection--->
<cffunction name="getmapname" access="remote" returntype="query" >
<cfargument name="mapfile" type="any" required="no" default="">
<cfargument name="Tributary" type="any" required="no" default="">
<!---Define variables--->
<cfset var data="">
<!---Get file html Data--->
<cfquery name="data" datasource="mydatasource">
SELECT CruiseDate, Tributary, File_html
FROM df_cruises
WHERE CruiseDate=<cfqueryparam cfsqltype='cf_sql_date' value='#ARGUMENTS.mapfile#'> AND Tributary=<cfqueryparam cfsqltype='cf_sql_varchar' value='#ARGUMENTS.Tributary#'> AND File_html<><cfqueryparam cfsqltype="cf_sql_varchar" value='notsampled'>
</cfquery>
<!---And return it--->
<cfreturn data>
</cffunction>
</cfcomponent>

CFM:

<cfparam name="url.File_html" default = '2'>
<cfform name="CruiseChoose" action="mapdisplayv3.cfm" method="post">
<table align="center" bgcolor="orange">
<tr>
<th colspan="2">
<font size="+1">First Select a Water Body, Then Choose Cruise Date</font>
</th>
</tr>
<tr>
<td>
<br />
Tributary/Water Body:<br />
<cfselect name="Tributary"
bind="cfc:GettingData.getData()"
display="Tributary"
value="Tributary"
bindonload="true"
multiple="no"
size="6" />
</td>
<td>
<br />
Cruise Dates:<br />
<cfselect name="CruiseDate"
bind="cfc:GettingData.getDates({Tributary})"
bindonload="false"
type="link"
display="date"
value="CruiseDate"
multiple="no"
size="6"/>
</td>
<td>
<br>
Map Links:<br />
<cfselect name="link"
bind="cfc:GettingData.getmapname({CruiseDate}, {Tributary})"
bindonload="false"
type="any"
display="File_html"
value="File_html"
multiple="no"
size="3"/>
</td>
</tr>
<tr>
<td colspan="2" align="center">
<br />
</form>
<!--- submit button --->
<cfoutput> <input type="submit" name="submit" value="View Selected Maps" alt="View Map Selection Button"><br></cfoutput>
<!--- Reset button. --->
<input name="reset" type="reset" value="Clear Selections" alt="Clear Selections Button">
</td>
</tr>
</table>
</cfform>
</html>

关于drop-down-menu - ColdFusion 中的动态依赖/三重相关选择,第三个不持有第一个选择,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36893740/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com