coldfusion 9动态调用方法 [英] coldfusion 9 dynamically call method
问题描述
我试图从已经传递到引用另一个对象的对象的字符串中构建方法调用。
I'm attempting to build a method call from strings that have been passed into an object that refer to another object.
正常情况下,当调用对象时,我们写代码如下:
normally when calling an object we write the code like this:
application.stObj.oNewsBusiness.getNews(argumentCollection=local.stArgs);
但是我所做的是创建一个包含对象名,方法名和参数的数组
However what I have done is created an array that contains the object name, the method name and the argument collection.
<cfscript>
local.stArgs = {};
local.stArgs.nNewsID = 19;
local.stArgs.sAuthor = "John";
local.aData = [];
local.aData[1] = local.stArgs;
local.aData[2] = "stObj.oNewsBusiness";
local.aData[3] = "getNews";
</cfscript>
然而我很难将所有这些都重新组合成一个方法调用。
however i am struggling to recombine all this to be a method call.
更新使用建议但仍然有问题
虽然cfinvoke似乎适用于:
While cfinvoke seems to work for:
<cfinvoke component="#application.stObj.oNewsBusiness#" method="#local.sMethod#" argumentcollection="#local.stArgs#" returnvariable="local.qData"></cfinvoke>
在执行以下操作时无效:
it doesn't work when doing something like:
<cfscript>
local.stArgs = local.aData[1];
local.sObject = local.aData[2];
local.sMethod = local.aData[3];
</cfscript>
<cfinvoke component="application.#local.sObject#" method="#local.sMethod#" argumentCollection="#local.stArgs#" returnvariable="local.qData"></cfinvoke>
会产生错误:
无法找到ColdFusion组件或接口application.stObj.oNewsBusiness
Could not find the ColdFusion component or interface application.stObj.oNewsBusiness
推荐答案
p> CFInvoke通常用于处理动态方法调用。
CFInvoke is generally used to handle dynamic method calls.
http://help.adobe.com/en_US/ColdFusion/9.0/CFMLRef/WSc3ff6d0ea77859461172e0811cbec22c24-7e0a.html
CFInvoke有一个argumentcollection属性,所以你可以传递你的参数以你习惯的方式。
CFInvoke has an argumentcollection attribute so you can pass your arguments in the way you are used to.
这篇关于coldfusion 9动态调用方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!