我有一个具有多个功能的cfc文件(info.cfc),如下所示。
<cfcomponent output="true" extends="DateFunctions"> <cffunction name="getStatuses" access="remote" returntype="any" output="true" returnformat="plain"> ... </cffunction> <cffunction name="viewDate" access="remote" returntype="any" output="true" returnformat="plain"> <cfquery name="records"> SELECT dbo.tickets.Incident, dbo.tickets.Start_Date, dbo.tickets.Days_Due FROM dbo.tickets </cfquery> </cffunction> </component>
另一个cfc文件(DateFunctions.cfc)包含带有两个参数的a函数并返回日期。DateFunctions.cfc文件如下:
<cfcomponent output="true" name="DateFunctions""> <cffunction name="addBusinessDays" access="remote" returntype="any" output="true" returnformat="plain"> <cfargument name="daysToAdd" required="yes" type="numeric" hint="The number of whole business days to add or subtract from the given date"> <cfargument name="date" required="No" type="date" hint="The date object to start counting from.." default="#NowDateTime#"> ... ... <!--- Perform some tasks ---> <cfreturn Date> </cffunction> </cfcomponent>
问题:如何在(info.cfc)中的查询中调用“ addBusinessDays”,也会产生另一列结果。
我以为我可能可以做类似的事情:
<cffunction name="viewDate" access="remote" returntype="any" output="true" returnformat="plain"> <cfquery name="records"> SELECT dbo.tickets.Incident, dbo.tickets.Start_Date, dbo.tickets.Days_Due, ( <cfinvoke component="DateFunctions" method="addBusinessDays" returnVariable="Date"> <cfinvokeargument name="daysToAdd" value="#dbo.tickets.Days_Due#"> <cfinvokeargument name="date" value="#dbo.tickets.Start_Date#"> </cfinvoke> ) AS Due_DATE FROM dbo.tickets </cfquery> </cffunction>
请注意以下事项,该循环还会有其他处理。
编辑:根据下面的讨论,将cfoutput更新为cfloop
<cffunction name="viewDate" access="remote" returntype="any" output="true" returnformat="plain"> <cfquery name="records"> SELECT dbo.tickets.Incident, dbo.tickets.Start_Date, dbo.tickets.Days_Due, '' as Due_DATE FROM dbo.tickets </cfquery> <cfset df = createobject("component","DateFunctions")> <cfloop query="records"> <cfset records.Due_DATE = df.addBusinessDays(Days_Due, Start_Date)> </cfloop> <cfreturn records> </cffunction>