问题
I want to have an argument like this:
<cfargument
name="exclude"
type="list"
required="false"
default="-1"
hint="A list of source IDs that should be excluded"
>
I don't see it in the docs at http://livedocs.adobe.com/coldfusion/8/htmldocs/help.html?content=Tags_a-b_6.html by I don't really trust them.
Does anyone know if this is possible or will I have to convert to an array?
At the moment I get an error:
The EXCLUDE argument passed to the renderSelectSource function is not of type list.
It's not complaining that "list" is not a valid type, but maybe it's just a bad error message.
回答1:
The type in this case would be "string". A list is just a string.
You could do the conversion to array... but unless it buys you something that I'm not seeing, I don't see the issue with just declaring the argument as a string.
回答2:
What I usually do in this situation is allow for either a delimited string (i.e. a list) or an array. In particular this lets you deal with situations where your array value contains the delimiter (i.e. a comma). For example:
<cffunction name="myFunction" output="false" access="public" returntype="any" hint="">
<cfargument name="multiValuedArg" type="any" required="true"/>
<cfif isSimpleValue(arguments.multiValuedArg)>
<cfset arguments.multiValuedArg = listToArray(arguments.multiValuedArg)>
<cfelseif NOT isArray(arguments.multiValuedArg)>
<cfthrow type="java.lang.IllegalArgumentException"
message="'multiValuedArg' argument must be an array or comma delimited list">
</cfif>
</cffunction>
来源:https://stackoverflow.com/questions/6282327/can-a-cfargument-be-of-type-list