从 Coldfusion 方法调用返回查询时遇到问题
好的,我已经实例化了一个对象,一切都很好。我可以轻松调用该对象的各种方法,例如 myobject.getId()、myObject.getName() 等。这些示例都返回字符串或数值。
现在我有另一种返回查询的方法。我已经 cfdumped 该方法返回的内容,它确实是一个正在返回的查询。
当我尝试 cfloop 查询时,出现错误。
这是 cfloop 代码:
<cfloop query="myObject.myFunction()">
<p><cfoutput>#myObject.myFunction().title#</cfoutput></p>
</cfloop>
我得到的错误引用了第一行并说:
无效的变量声明 [myObject.myFunction()]
有什么想法吗?提前致谢!
Ok, I have instantiated an object and all is fine. I am able to call various methods of that object easily, such as myobject.getId(), myObject.getName() , etc etc. These examples all return either a string or numeric value.
Now I have another method that returns a query. I've cfdumped what is returned by the method and it is indeed a query that's being returned.
By when I try to cfloop through the query I get an error.
Here's the cfloop code:
<cfloop query="myObject.myFunction()">
<p><cfoutput>#myObject.myFunction().title#</cfoutput></p>
</cfloop>
The error I get references the very first line and says:
invalid variable declaration [myObject.myFunction()]
Any thoughts? Thanks in advance!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
好的,所以您只需要稍微更改您的代码,以便您首先调用运行查询,例如
,然后您可以循环它。
原因是
标记需要一个查询对象,而不是对函数的引用。您可以尝试查看
是否有效(使用 #'s),但我不确定是否有效。此外,循环内的每个调用(即#myObject.myFunction().title
)都将重新运行查询。明显不好啊!希望有帮助!
OK, so you just need to change your code slightly so you are doing call to run the query first, e.g.
And then you can loop over it.
The reason is that the
<cfloop/>
tag expects a query object, not a reference to a function.You could try to see if
<cfloop query="#myObject.myFunction()#">
works (with the #'s) but I'm not sure if it will. Besides, each call inside the loop i.e.#myObject.myFunction().title
is going to re-run the query. Not good obviously!Hope that helps!