Can a cfargument be of type “list”?

非 Y 不嫁゛ 提交于 2019-12-11 04:01:54

问题


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

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