【发布时间】:2013-06-05 00:36:58
【问题描述】:
我在 Coldfusion cfscript 中尝试做的是遍历请求的变量集合并进行一些评估,这在 PHP 中可以轻松完成,但在转换为 Coldfusion cfscript 时遇到了问题,因为我似乎无法构建动态if 语句
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 语句改成这样,一样
if (rc.bSearchable_+i EQ true and rc.sSearch+i NEQ '') {
最后我尝试构建一个字符串并使用它,我知道它不起作用但我想我会试一试,错误是无法将 var 转换为布尔值
for (i=1; i<= iColumnsLen; i++) {
var iterator = "rc.bSearchable_"&i&" EQ true and rc.sSearch_"&i&" NEQ ''";
if (#iterator#) {
这是我希望有问题地完成的没有迭代的静态冷融合
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 ";}
}
任何帮助都会非常感激
【问题讨论】:
-
我试过了,出错了。错误信息是什么?仅供参考:
URL范围是一个结构。您可以使用关联数组表示法动态访问这些值:即url["someFixedName"& counterVariable ]。 -
.. 这同样适用于任何结构。
标签: coldfusion cfml coldbox