ColdFusion 已定义 [英] ColdFusion isDefined
本文介绍了ColdFusion 已定义的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试检查我的表单中是否存在数据如果数据不存在我想将其分配给 O.我该怎么做.
I am trying to check to see if data exist in my form If data does not exist I want to assign it to O. How can I do this.
<cfif not isDefined("FORM.Age")>
cfset FORM.Age = "0"
<cfif>
推荐答案
一般认为最好的做法是避免isDefined.这是因为 isDefined 将搜索所有范围,直到找到匹配的变量.所以使用structKeyExists效率更高,例如:
Generally the best practice is considered to be to avoid isDefined. This is because isDefined will search all scopes until it finds a matching variable. So it's more efficient to use structKeyExists, eg:
<cfif NOT structKeyExists(form, "age")>
<cfset form.age = 0>
</cfif>
另外,实现此目的的另一种方法是使用 cfparam,并指定 0 作为默认值:
Also, another way to achieve this is to use cfparam, and specify 0 as the default:
<cfparam name="form.age" default="0">
这篇关于ColdFusion 已定义的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文