ColdFusion isDefined [英] ColdFusion isDefined

查看:152
本文介绍了ColdFusion isDefined的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图检查我的表单中是否存在数据如果数据不存在,我想将其分配给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 isDefined的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆