Dynamic Variable Names Coldfusion

牧云@^-^@ 提交于 2019-12-06 12:09:13

This definitely won't work, it's not valid CFML:

getListingInformation.#catNameNoSpace#

Evaluate is the devil, but you can use the array-style syntax instead. The only caveat is that you need to explicitly specify the row from which you want the value to come (and if the query has no rows, this will error out).

getListingInformation[catNameNoSpace][1]

Sixten's answer has a syntax you can use, but you'll still need to watch out for illegal characters in variable names as answered elsewhere. The ultimate guide for variables is here: http://www.depressedpress.com/Content/Development/ColdFusion/Articles/Variables/Index.cfm, especially this section http://www.depressedpress.com/Content/Development/ColdFusion/Articles/Variables/NotationIndexed.cfm

Slightly different but might be useful to anyone looking at this: You can also use Variables["staticPartOfVariableName#DynamicPartOfVariableName#"] .

Alright I think I figured it out. I don't really like how I had to do it though.

evaluate("getListingInformation.#catNameNoSpace#")

I've heard somewhere before that using evaluate is slow and not very clean. Is there a better option?

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!