ColdFusion中的动态下拉列表9 [英] Dynamic Drop Down List in ColdFusion 9

查看:335
本文介绍了ColdFusion中的动态下拉列表9的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

好吧,所以人们不清楚我的问题,所以我删除了那里有一个问题已经问了别人,我没有得到完美的答案的网址。

Alright so people were not understanding clearly my question, so I removed the url where there was a question already asked by someone else and there I didn't got the perfect answer..

这里是问题........

So here is the Question........

我正在寻找ColdFusion中的一个动态下拉列表。我想要的是由上述下拉列表填充的下拉列表(例如:选择省(B.C)将填充城市下拉列表中该省内的所有城市)。省份数据将从ColdFusion查询中收集,并与城市的数据相同。

I am looking to code a dynamic drop down list within ColdFusion. What I want is the drop down list to be populated by the above drop down list (example: Select Province (B.C) will populate the City drop down list with all cities within that Province). Province data will be collected from a ColdFusion query and same with the city's data.

请,没有JavaScript,没有AJAX,没有ColdFusion CFCs,没有更多或少于一些ColdFusion标签... :(逻辑代码应该在一个.cfm档案本身。

Please, No JavaScript, No AJAX, No ColdFusion CFCs, Nothing more than or less than some ColdFusion Tags... :( The logic code should be in one .cfm file itself.


  • 编辑 -

@Charles Higgins

@Charles Higgins

似乎无法使它工作。它抛出错误调用CFC BinFcns.cfc:内部服务器错误请告诉我在哪里它是错误的,这里是代码..

Can't seem to make it work. It's throwing "Error invoking CFC BinFcns.cfc : Internal Server Error" "Please tell me where I'm doing it wrong, here is the code..

这是一个'index.cfm'

This one is 'index.cfm'

<cfquery name="qstates" datasource="info">
  SELECT states
  FROM info

  GROUP BY states
</cfquery> 
<html> 
<head> 
</head> 
<body> 
<cfform>
<cfselect name="DropDown1" bind="cfc:BinFcns.Method({DropDown1})">
    <cfoutput query="qstates"><option>#states#</option></cfoutput>
</cfselect>
<cfselect name="DropDown2" bind="cfc:BinFcns.Method({DropDown1})" /> 
</cfform>
</body> 
</html>

,这一个是.cfc,'BinFcns.cfc'

and this one is the .cfc, 'BinFcns.cfc'

<cfcomponent output="true">
   <!--- set function name --->
   <cffunction name="Method" access="remote" returnType="array">
    <!--- this is what you passed to the CFC via the {} think in the select --->
      <cfargument name="Selected" type="numeric" required="true">
      <!--- Define array to produce the drop down --->
      <cfset var data="">
      <cfset var result=ArrayNew(2)>
      <cfset var i=0>
      <!--- Get data --->
      <cfquery name="data" datasource="info">
      SELECT *
      FROM info
      Order by cities
      </cfquery> 
      <!--- Convert results to array --->
      <cfloop index="i" from="1" to="#data.RecordCount#">
             <cfset result[i][1]=data.DropDownID[i]>
             <cfset result[i][2]='#DropDownTEXT#'>      
             <!--- determine which is selected via what you passed and something in the database --->
            <cfif data.DropDownID[i] eq #Selected#>
                <cfset result[i][3]=true>
            </cfif>
      </cfloop>

      <!--- And return it --->
      <cfreturn result>
   </cffunction>
</cfcomponent>     


推荐答案

您的CFC它不复杂,最好的选择,我没有测试这个代码,但它应该接近工作..只是象我的大多数代码。真的像我的代码。

Your CFC Its not complicated, trust me learn its the best option, I have not tested this code but it should be close to working.. just fugly like most of my code.

<cfcomponent output="false">
   <!--- set function name --->
   <cffunction name="Method" access="public" returnType="array">
    <!--- this is what you passed to the CFC via the {} think in the select --->
      <cfargument name="Selected" type="numeric" required="true">
      <!--- Define array to produce the drop down --->
      <cfset var data="">
      <cfset var result=ArrayNew(2)>
      <cfset var i=0>
      <!--- Get data --->
      <cfquery name="data" datasource="#THIS.dsn#">
      SELECT *
      FROM 2ndDropDownData
      Order by DataName
      </cfquery> 
      <!--- Convert results to array --->
      <cfloop index="i" from="1" to="#data.RecordCount#">
             <cfset result[i][1]=data.DropDownID[i]>
             <cfset result[i][2]='#DropDownTEXT#'>      
             <!--- determine which is selected via what you passed and something in the database --->
            <cfif data.DropDownID[i] eq #Selected#>
                <cfset result[i][3]=true>
            </cfif>
      </cfloop>

      <!--- And return it --->
      <cfreturn result>
   </cffunction>
</cffunction>      

CFM SIMPLE!

The CFM SIMPLE!

下拉称为DropDown1,然后你通过下面的代码传递到cfc下拉2

A drop down called DropDown1, then you pass that to the cfc via the following code for drop down 2

<cfselect name="DropDown2" bind="cfc:cfcname.Method({DropDown1})" /> 

它简单...两个下拉列表,第二个调用CFC ..值得学习。

Its that simple... two drop downs, with the second one calling the CFC.. Worth learning.

您可以使用Bindonload在第二个预先选择,如果需要。

You can use Bindonload, on the 2nd to preselect if required.

无论如何,希望阻止你害怕CFCs ..他们是非常有用的。

Anyway hope that stops you being scared of CFCs.. they are very usefull.

这篇关于ColdFusion中的动态下拉列表9的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆