cfset 标签中的 cfoutput

cfoutput in cfset tag

我需要在 cfset 标记中使用 cfoutput 来获取要发送的多个订单项 xml。我知道将 CF 标签放入另一个标签是错误的,但我正在寻找执行此操作的最佳方法。提前致谢。

<cfset soapBody = soapBody & "
    <cfoutput query="getitems">                        
    <item id=""#id#"">
        <unitPrice>#getitems.unitprice#</unitPrice>
        <quantity>#getitems.quantity#</quantity>
        <productname>#getitems.productname#</productname>
        <taxAmount>#getitems.taxamount#</taxAmount>
        <unitOfMeasure>#getitems.unitofmeasure#</unitOfMeasure>
        <taxRate>#getitems.taxrate#</taxRate>
        <totalAmount>#getitems.totalamount#</totalAmount>
        <grossNetIndicator>#getitems.grossnetindicator#</grossNetIndicator>
    </item>
    </cfoutput>         
">

您可以为此使用 <cfsavecontent> 标签。它非常适合您尝试动态创建一大段字符串的情况。

<cfsavecontent variable="soapBody">
    <cfoutput>#soapBody#</cfoutput>
    <cfoutput query="getitems">                        
    <item id=""#id#"">
        <unitPrice>#getitems.unitprice#</unitPrice>
        <quantity>#getitems.quantity#</quantity>
        <productname>#getitems.productname#</productname>
        <taxAmount>#getitems.taxamount#</taxAmount>
        <unitOfMeasure>#getitems.unitofmeasure#</unitOfMeasure>
        <taxRate>#getitems.taxrate#</taxRate>
        <totalAmount>#getitems.totalamount#</totalAmount>
        <grossNetIndicator>#getitems.grossnetindicator#</grossNetIndicator>
    </item>
    </cfoutput>         
</cfsavecontent>