是否有cfscript支持在具有group属性的查询上循环



我正在Adobe ColdFusion 10中运行以下代码。我想删除所有标签,并在脚本中执行此操作。真实的代码更复杂,这只是一个用于演示的外壳。

对此有任何cfscript支持吗?您应该能够按照原样复制和粘贴此代码,作为我试图实现的一个示例。

<h1>Task Migration</h1>
<cfscript>
    id=0;
    commentid=0;
    qryTasks = queryNew("tasknumber,name,commentid,comment"
                        ,"integer,varChar,integer,varChar"
                        ,[ 
                            { 
                                tasknumber : ++id
                                ,name : "Task Name for #id#"
                                ,commentid: ++commentid
                                ,comment : "comment #commentid# on tasknumber #id#"
                            }
                            ,{ 
                                tasknumber : id
                                ,name : "Task Name for #id#"
                                ,commentid: ++commentid
                                ,comment : "comment #commentid# on tasknumber #id#"
                            }
                            ,{ 
                                tasknumber : ++id
                                ,name : "Task Name for #id#"
                            }
                            ,{ 
                                tasknumber : ++id
                                ,name : "Task Name for #id#"
                                ,commentid: ++commentid
                                ,comment : "comment #commentid# on tasknumber #id#"
                            }
                        ] 
                );  
    writedump(var:qryTasks, label:"starting query");
    traceLog=[];
</cfscript>
<cfloop query="qryTasks" group="tasknumber">
        <cfscript>
            arrayAppend(traceLog, "Make a ticket for #qryTasks.name#");
        </cfscript>
        <cfloop group="commentID">
            <cfscript>
                if (trim(qrytasks.comment) != ''){
                    arrayAppend(traceLog, "Add comment to #qryTasks.name#: #qrytasks.comment#");
                };
            </cfscript>
        </cfloop>
</cfloop>
<cfdump var="#tracelog#" label="Stuff that happened in the loop" />

回答"不可能"。有变通办法,但我对此不感兴趣。RAILO做到了,Adobe CF11也做到了。但在ACF10 中不可行

在Using CFScript语句文档中有以下循环查询的示例。如果您在查询中定义了分组,那么它可能会为您提供所需的内容。

用于构造中(用于查询)

类似于在数组和结构上循环,在构造中使用for,可以在CFScript中在查询对象上循环。

示例

在本例中,查询结果集在变量art中可用,for In循环用于在结果集上循环。在for in构造中使用的变量行是一个包含查询列作为键的结构。您可以使用arts.currenttrow引用当前行。

<cfquery name="arts" datasource="cfartgallery"> 
    select * from art 
</cfquery> 
<cfscript> 
    cols = listToArray(listsort(arts.columnlist, "textnocase")); 
    for(row in arts) 
    { 
        for(col in cols) 
            writeoutput(arts.currentrow & " ..." & col & ": " & row[col] & "<br>"); 
        writeoutput("<hr>"); 
    } 
</cfscript>

注意:您必须在queryname前面加前缀才能访问查询结果变量,如记录计数或当前行(如示例所示)。

最新更新