使用CF列表循环创建组合 [英] Creating Combinations using CF List Loops

查看:78
本文介绍了使用CF列表循环创建组合的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在从事Coldfusion项目,但似乎被困住了.我是新手,所以我希望我不要太懈怠.我的项目的目的是通过使用嵌套循环来创建密码列表.我要设计一个模板,该模板将列表冷,融合,动态"中的所有单词与列表"bert,ernie,oscar"中的所有单词结合在一起,以生成带符号的有效密码列表.该模板应处理两个名为List1和List2的URL参数.我必须使用彼此嵌套的两个列表循环来产生所有可能的单词组合. (例如"coldbert","coldernie","coldoscar","fusionbert"等.)

I'm working on a Coldfusion project and I seem to be stuck. I am a newbie so I hope I don't get too much slack. The purpose of my project is to create a password list by using nested loops. I am to design a template that combines all words in the list "cold, fusion, dynamic" with all words on the list "bert, ernie, oscar" to produce a bulleted list of vaild passwords. This template should process two URL prarameters named List1 and List2. I must use two list loops nested within each other to produce all possible combinations of words. (For example "coldbert", "coldernie", "coldoscar", "fusionbert" and so on..)

这是我到目前为止所拥有的:

This is what I have so far:

<cfinclude template="header.cfm">
<body>

<h2>Loop List</h2>


<cfhttp url="looplist.cfm?List1=cold,fusion,dynamic&List2=bert,ernie,oscar" method="get">

<CFLOOP LIST="#URL.List1#"
INDEX="List1">
<UL><CFOUTPUT>#List1#</CFOUTPUT></UL><br>
</CFLOOP>


<cfinclude template="footer.cfm">

我想确保在这里朝正确的方向前进.谢谢大家的帮助.

I want to ensure that I'm going in the right direction here. Thanks guys for any assistance.

推荐答案

除非您要调用的网站不存在该页面,否则我认为不需要进行http调用.您可以只在模板中创建一个函数(尽管我希望它在单独的cfc中),然后调用该函数来获取密码组合.像...

Unless you're calling a page that doesn't exist on your site, I do not see a need to do a http call. You could just create a function in the template (although I'd prefer it to be in a separate cfc) and call that to get your password combos. Something like ...

<cffunction name="getPasswordCombos" returntype="string">
    <cfargument name="list1" type="string" required="true" />
    <cfargument name="list2" type="string" required="true" />

    <cfset var passwordCombos = "" />
    <cfset var i = "" />
    <cfset var j = "" />

    <!--- your combo generation logic might look something like --->
    <cfloop list="#arguments.list1#" index="i">
        <cfloop list="#arguments.list2#" index="j">
            .....
            <!--- set passwordCombos logic here --->
            .....
        </cfloop>           
    </cfloop>

    <cfreturn passwordCombos />
</cffunction>

然后

<cfset passwordCombos = getPasswordCombos("cold,fusion,dynamic", "bert,ernie,oscar") />

然后循环遍历"passwordCombos"

Then loop over the "passwordCombos"

<ul>
    <cfloop list="#passwordCombos#" index="i">
        <li>#i#</li>
    </cfloop>
</ul>

此外,如果您必须使用CFHTTP用户,请使用cfhttpparam传递参数.干净得多.

Also, if you HAVE to user CFHTTP, use cfhttpparam to pass in arguments. It's much cleaner.

<cfhttp result="result" url="looplist.cfm" method="GET">
    <cfhttpparam name="list1" type="url" value="cold,fusion,dynamic">
    <cfhttpparam name="list2" type="url" value="bert,ernie,oscar">
</cfhttp>

这篇关于使用CF列表循环创建组合的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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