从解析的字符串创建两个变量 [英] Create two variables from parsed string

查看:90
本文介绍了从解析的字符串创建两个变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将字符串解析为两个变量.源是一个SQL查询,该查询填充多个复选框的值.复选框的数量根据查询结果而有所不同.复选框编码为:

I'm trying to parse a string into two variables. The source is a SQL query that populates values for multiple checkboxes. The number of checkboxes varies base on the query results. The checkboxes are coded:

<input type="checkbox" name="Listname" value="#RecID#:#DistListName#" ID="ListName#ListID#">

使用在这里找到的代码,我将:移除,将RecID和DistListName分隔为:

Using code I found here, I remove the : separating RecID and DistListName with:

<cfset PreParseList = #form.Listname#>    
<cfset ParseList = ListToArray(PreParseList, ":", false, true)>

ParseList的输出如下所示:

The output of ParseList looks like this:

627 Corporate IT Desktop Team DL,629 Corporate IT Helpdesk Team DL,607 HMC Behavioral Health DL,257 Kauai Region HR

我需要创建两个变量,一个用于RECID,可以是1到3位数字,另一个用于名称. RecID将写入联结表,该联结表控制用户可以访问的分发列表.名称仅显示在确认页面上.

I need to create two variables, one for the RECID which can be 1 to 3 digits long, and one for the name. The RecID gets written to a junction table that controls what distribution lists a user would have access to. The name is just displayed on the confirmation page.

我是否正在尝试,还是应该研究一种不同的方式来传递RecID和名称?

Is what I'm trying even possible, or should I look into a different way of passing the RecID and name?

推荐答案

<cfset recIds = []>
<cfset distListNames = []>
<cfloop list="#form.Listname#" index="checkboxValue">
  <cfset arrayAppend(recIds, listFirst(checkboxValue, ':'))>
  <cfset arrayAppend(distListNames, ListRest(checkboxValue, ':'))>
</cfloop>

我应该研究一种不同的方式来传递RecID和名称吗?

should I look into a different way of passing the RecID and name?

将复选框的值仅设置为RecID是合乎逻辑的,因为名称仅显示在确认页面上".然后,您可以从form范围中免费获取一个RecIDs列表,以备使用.确认页面是CFM页面吗?如果是这样,您是否无法显示通过ID从数据库再次获取的名称?

It'd be logical to only set the value of checkbox to RecID, since "the name is just displayed on the confirmation page". Then you get a list of RecIDs from the form scope, ready to be used, for free. Is the confirmation page a CFM page? If so, couldn't you display the name(s) that by fetching from DB again by ID(s)?

这篇关于从解析的字符串创建两个变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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