Ale*_*hen 2 coldfusion switch-statement
我有一个像这样的switch语句:
<cfswitch expression="#action#">
<cfcase value="caseone">
// do task one
</cfcase>
<cfcase value="casetwo">
// repeat task one
// Also do another task here
</cfcase>
</cfswitch>Run Code Online (Sandbox Code Playgroud)
有没有一种简单的方法可以重复casein的caseone相同的任务?(而不是从caseone复制长片代码)
你可以这样做:
创建一个函数,在那里执行任务,并从两个cfswitch案例中调用该函数,如下所示:
<cffunction name="taskOne">
do task one
</cffunction>
<cfswitch expression="#action#">
<cfcase value="caseone">
<cfset taskOne() >
</cfcase>
<cfcase value="casetwo">
<cfset taskOne() >
// Also do another task here
</cfcase>
</cfswitch>
Run Code Online (Sandbox Code Playgroud)