【问题标题】:ColdFusion ORM Call method from EntityLoad in cfscriptcfscript 中 EntityLoad 的 ColdFusion ORM 调用方法
【发布时间】:2012-02-13 05:38:17
【问题描述】:

我正在尝试做一些我认为非常基本的事情,但我无法让它发挥作用。我这样调用EntityLoad:

<cfscript>

   transaction {

       dataLoad = EntityLoad("trans");  
   }

</cfscript>

现在,如果我基于标签进行操作,我可以遍历它并调用如下方法:

<cfloop array="#dataLoad#" index="x">

    <cfoutput>#x.getCompanyName()#</cfoutput>

</cfloop>

但我正在尝试在 cfscript 中执行此操作。我能想到的最接近的事情是:

<cfscript>

    for (x=1;x <= ArrayLen(dataLoad);x=x+1){

        writeOutPut(dataLoad.companyName());            

    }

</cfscript>

我知道cfscript中的for循环和cfloop数组不一样。 cfscript中没有等效于cfloop的数组吗?

如果不是,我如何从 cfscript 调用 EntityLoad 中的方法?

提前感谢您的帮助。

【问题讨论】:

  • 以下是两种不同的方法。这两点我都应该知道。我把答案给了 Sam,因为它是最简单、最少的代码。

标签: hibernate orm coldfusion


【解决方案1】:
for ( var x in dataLoad ) {
 x.getCompanyName();
}

【讨论】:

  • 使用 for ( x in array ) 是 CF9 中的新功能,如果您想知道为什么它不能在您的 CF6/7/8 实例上运行
  • 如果您正在使用 cfscript 事务,可以安全地假定您已经在运行 CF9 :)
【解决方案2】:

替换

writeOutPut(dataLoad.companyName());

writeOutPut(dataLoad[x].getCompanyName());

这应该可以解决错误。

【讨论】:

    【解决方案3】:

    试试这个:

    <cfscript>
    
    transaction {
        dataLoad = entityLoad("trans");
    }
    
    for ( var i = 1; i <= arrayLen( dataLoad ); i++ ) {
        writeOutput( dataLoad[i].companyName() );
    }
    
    </cfscript>
    

    在cfscript中循环数组时,需要在每次迭代时指定索引。

    【讨论】:

      猜你喜欢
      • 2010-11-19
      • 1970-01-01
      • 1970-01-01
      • 2013-05-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多