문제

If I have

<cfset methodName = "a">
<cfset object = createObject(...)>

How can I call the function named methodName from the component object. I would expect something along the lines of

<cfset object[methodName]()>

as would work in JS, but this doesn't seem to work. I know that I could use a cfinvoke, however I don't think I need to delve into the reasons why I do not want to use that tag (using it as a temporary fix right now).

도움이 되었습니까?

해결책

There is cfinvoke as well as invoke() in Adobe ColdFusion 10+ for script-based code.

다른 팁

You can set the unknown/dynamic method to an explicit key in the object and execute it from that key:

<cfset methodName = "a">
<cfset object = createObject(...)>
<cfset object.doMethod = object[methodName]>
<cfset object.doMethod()>

Still not very elegant, but it avoids <cfinvoke> and evaluate().

It's klutzy but, you could always write the line of code to a .cfm file and then cfinclude it.

cfinvoke or evaluate('object.#a#()') (be sure that you can trust a)

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top