gpt4 book ai didi

json - cfloop 在 startrow 之前返回空数组

转载 作者:行者123 更新时间:2023-12-04 20:00:12 25 4
gpt4 key购买 nike

下午好。目前我正在从查询中格式化一些 json,当我到达循环查询的地步时,我发现了一个非常奇怪的现象。我将 startrow 指定为 20,将 endrow 指定为 40。运行时,我在填充 20-40 之前得到 19 个空数组。如何让循环只返回第 20-40 行?

<cfcontent reset="Yes" />
<cfset thedata = StructNew() >
<cfset thestruct = StructInsert(thedata, "sEcho", "#NumberFormat(val(url.sEcho),"_")#", 1)>
<cfset thestruct = StructInsert(thedata, "iTotalRecords", "#NumberFormat(qCount.total,"_")#", 1)>
<cfset thestruct = StructInsert(thedata, "iTotalDisplayRecords", "#NumberFormat(qFiltered.recordCount,"_")#", 1)>
<cfset thearray = ArrayNew(2)>
<!--- Populate the array row by row --->

<cfloop query="qFiltered" startrow="20" endrow="40">
<cfset thearray[CurrentRow][1]=req_name>
<cfset thearray[CurrentRow][2]=req_departments_name>
<cfset thearray[CurrentRow][3]=dest_departments_name>
<cfset thearray[CurrentRow][4]=priority_rank_name>
<cfset thearray[CurrentRow][5]=issue_subject>
<cfset thearray[CurrentRow][6]=systems_sub_name>
<cfset thearray[CurrentRow][7]=tickets_status_name>
<cfset thearray[CurrentRow][8]=tickets_types_name>
<cfset thearray[CurrentRow][9]=due_date>
<cfset thearray[CurrentRow][10]=departments_sub_name>
</cfloop>
<cfset thestruct = StructInsert(thedata, "aaData", thearray, 1)>
<cfoutput>#serializeJSON(thedata)#</cfoutput>

返回这个 JSON

{
"iTotalDisplayRecords":"202",
"iTotalRecords":"661",
"aaData":[
[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],
["Derek Wolf","","","02- Revenue","Assist in validating error in JCA provided Discount Commission report","","Received","Work Request","Jan 1, 2012",""],
["Katie Hintz","","","02- Revenue","Order\/Install new POS Terminal at Katie's Workstation","","In Progress","Work Request","Oct 31, 2011",""],
["Katie Hintz","","","02- Revenue","Replace #6081 POS Printer at Kim's Desk","","Received","Work Request","Oct 31, 2011",""],
["","","","02- Revenue","Produce Brought To You By... Video","","In Progress","Work Request","Nov 9, 2011",""],
["","","","02- Revenue","Produce Dept. Spotlight Video","","In Progress","Work Request","Nov 9, 2011",""],
["","","","02- Revenue","Produce Matty T's Pancake Breakfast","","In Progress","Work Request","Nov 9, 2011",""],
["","","","02- Revenue","Produce Fish! Video","","In Progress","Work Request","Nov 9, 2011",""],
["Sextus Selvaratnam","","","02- Revenue","Larger coin hopper system","","In Progress","Work Request","",""],
["Charles Canfield","","","02- Revenue","Ride theme improvment Castle","","In Progress","Work Request","",""],
["Omid Aminifard","","","02- Revenue","Contact Alterface about Desperados","","In Progress","Work Request","",""],
["Dino Kypreos","","","03- Repair","Repair or Replace Radio","","Received","Work Request","",""],
["Josh Cohen","","","03- Repair","SQL Server maintenance and tuning","","In Progress","Work Request","",""],
["","","","03- Repair","Move Weather Station to new Ops area","","Approved","Work Request","Nov 30, 2011",""],
["","","","03- Repair","Weather Station Move","","Approved","Work Request","Nov 30, 2011",""],
["","","","03- Repair","Strip and clean Moving Light fixtures","","Waiting Approval","Work Request","Dec 31, 2011",""],
["","","","03- Repair","Strip and clean Source Four light Fixtures","","Waiting Approval","Work Request","Dec 31, 2011",""],["","","","03- Repair","Replace Bad LCDs on ColorDash Pars LED light","","Received","Work Request","Dec 31, 2011",""],
["Josh Cohen","","","03- Repair","OMRON: repair terminal 4 computer","","On hold by originator","Work Request","",""],
["Amy Walters","","","03- Repair","Radio\/pager maintenance","","Waiting on parts","Work Request","",""],
["Mark Hersey","","","03- Repair","Inspect Ride Speaker Mounts for Safety","","Received","Work Request","Sep 30, 2011",""],
["Brian Gustav","","","03- Repair","Radio\/pager maintenance","","In Progress","Work Request","",""]],
"sEcho":"1"
}

更新

John 能够为我找到答案。现在我已经开始工作了,我想从列表中生成所有 CFSET 标签

<cfset listColumns = "tickets_id,departments_sub_name,aging,priority_rank_name,systems_sub_name,issue_subject,tickets_status_name,due_date" />

<cfloop list="#listColumns#" index="thisColumn" delimiters=",">
<cfset rowarray[listColumnsCount]=#thisColumn#>
<cfset listColumnsCount ++>
</cfloop>

我只是获取 JSON 中的列名,而不是获取列值输出

最佳答案

您的问题是您正在使用 CurrentRow 作为 thearray 的第一个索引。因此,即使您的 cfloop 正确地跳过了前 19 行,您还是告诉它把第一个放在数组中的第 20 个位置,所以您在此之前得到 19 个空的。

您可以手动从 CurrentRow 值中减去 19,但每次更改 startrow 时都必须更改计算。

更好的选择是单独构建内部数组,然后将其ArrayAppendthearray。无论您的 startrowendrow 值如何,这都将起作用。

<cfloop query="qFiltered" startrow="20" endrow="40">
<cfset rowarray = ArrayNew(1)>
<cfset rowarray[1]=req_name>
<cfset rowarray[2]=req_departments_name>
<cfset rowarray[3]=dest_departments_name>
<cfset rowarray[4]=priority_rank_name>
<cfset rowarray[5]=issue_subject>
<cfset rowarray[6]=systems_sub_name>
<cfset rowarray[7]=tickets_status_name>
<cfset rowarray[8]=tickets_types_name>
<cfset rowarray[9]=due_date>
<cfset rowarray[10]=departments_sub_name>
<cfset ArrayAppend(thearray, rowarray)>
</cfloop>

关于json - cfloop 在 startrow 之前返回空数组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7680014/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com