通过动态评估通过url请求集合变量进行迭代 [英] Iteration through url request collection variables by dynamic evaluation

查看:81
本文介绍了通过动态评估通过url请求集合变量进行迭代的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Coldfusion cfscript中尝试做的事情是通过变量的请求集合进行迭代并进行一些评估,我可以在PHP中轻松地做到这一点,但是在转换为Coldfusion cfscript时遇到了问题,因为似乎我无法构建动态if语句

What i am trying todo in coldfusion cfscript is iterate through a request collection of variables and do some evaluation, which i can do easily in PHP, but am running into issue translating to coldfusion cfscript, because it seems i cannot build a dynamic if statement

PHP

for ( $i=0 ; $i<count($aColumns) ; $i++ )
    {
        if ( $_GET['bSearchable_'.$i] == "true" && $_GET['sSearch_'.$i] != '' )
        {
            //If there was no where clause
            if ( $sWhere == "" )
            {
                $sWhere = "WHERE ";
            }
            else
            {
                $sWhere .= " AND ";
            }

我已经尝试过,错误了

for (i=1; i<= iColumnsLen; i++) {   
  if (rc.bSearchable_&i EQ true and rc.sSearch&i NEQ '') {
            if ( sWhere EQ "" )
            { sWhere = " WHERE "; }
            else
            { sWhere &= " AND ";}
  }         
}

还尝试将if语句行更改为此,

also tried changing the if statement line to this, same

if (rc.bSearchable_+i EQ true and rc.sSearch+i NEQ '') {

最后我尝试构建字符串并使用它,我知道它不会工作,但我想我会试一试,错误是无法将var转换为boolean

finally i attempted building a string and using that , i knew it wouldnt work but i thought i'd give it a shot, error was could not convert var to boolean

for (i=1; i<= iColumnsLen; i++) {
 var iterator = "rc.bSearchable_"&i&" EQ true and rc.sSearch_"&i&" NEQ ''";
  if (#iterator#) {

这是我想要的没有迭代的静态Coldfusion

Here's the static coldfusion without iteration that i am desiring to be done problematically

  if (rc.bSearchable_1 EQ true and rc.sSearch_1 NEQ '') {
            if ( sWhere EQ "" )
            { sWhere = " WHERE "; }
            else
            { sWhere &= " AND ";}
  }         
  if (rc.bSearchable_2 EQ true and rc.sSearch_2 NEQ '') {
            if ( sWhere EQ "" )
            { sWhere = " WHERE "; }
            else
            { sWhere &= " AND ";}
  } 
  if (rc.bSearchable_3 EQ true and rc.sSearch_3 NEQ '') {
            if ( sWhere EQ "" )
            { sWhere = " WHERE "; }
            else
            { sWhere &= " AND ";}                                     
  }

必须提供任何帮助

推荐答案

正如Leigh所说,您只需要引用这样的动态列即可:

As Leigh says, you just need to refer to dynamic columns like this:

rc["bSearchable_" & i] 
rc["sSearch_" & i]

这篇关于通过动态评估通过url请求集合变量进行迭代的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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