创建ColdFusion函数以根据10个分组的变化处理报告输出。输出正确显示数据分组和数量,但它没有正确的报告标题。例如,它应该为每个组显示5个不同的建筑物名称,但都具有相同的建筑物名称。
以下是调用函数的代码:
<cfoutput query="Output" group="#Group1Field#" >
<cfscript>
Group1Count = 0;
Group1Amount = 0;
</cfscript>
<h2>#eqInventoryHelper.getGroupingHeaderText(Group1, Output)#</h2></cfoutput>
以下是该函数的代码:
<cffunction name="getGroupingHeaderText" output="false">
<cfargument name="selectedGrouping" required="true" type="string"/>
<cfargument name="outputQuery" required="true" type="query"/>
<cfscript>
var result = "";
switch (arguments.selectedGrouping) {
case "Building" :
result = "Building: #arguments.outputQuery.building_code# - #arguments.outputQuery.building_name#";
break;
case "PI Name" :
result = "PI: #arguments.outputQuery.pi_name#";
break;
case "Custodial Code" :
result = "Custodial Code: #arguments.outputQuery.custodial_code# - #arguments.outputQuery.custodian_desc#";
break;
case "Manufacturer" :
result = "Manufacturer: #arguments.outputQuery.manufacturer_name#";
break;
case "Room Number" :
result = "Room Number: #arguments.outputQuery.building_room_number#";
break;
case "Current UC Fund" :
result = "Current UC Fund : #arguments.outputQuery.cur_uc_fnd#";
break;
case "Original UC Fund" :
result = "Original UC Fund: #arguments.outputQuery.orig_uc_fnd#";
break;
case "EFA Fund Source" :
result = "EFA Fund Source: #arguments.outputQuery.efa_fnd_src_cd#";
break;
case "Asset Status" :
result = "Asset Status: #arguments.outputQuery.asset_status_name#";
break;
}
return result;
</cfscript>
</cffunction>
有什么建议吗?
感谢。
答案 0 :(得分:0)
假设这类似于您实施的适用于您的代码,我会将此作为答案发布,以防将来对其他任何人都有好处。
只需将当前行值传递给函数,即可轻松访问查询中的该行,例如:
<h2>#eqInventoryHelper.getGroupingHeaderText(Group1, Output, Output.currentRow)#</h2></cfoutput>
<cffunction name="getGroupingHeaderText" output="false">
<cfargument name="selectedGrouping" required="true" type="string"/>
<cfargument name="outputQuery" required="true" type="query"/>
<cfargument name="whichRow" required="true" type="numeric"/>
<cfscript>
var result = "";
switch (arguments.selectedGrouping) {
case "Building" :
result = "Building: #arguments.outputQuery.building_code[arguments.whichRow]# - #arguments.outputQuery.building_name[arguments.whichRow]#";
break;