动作(弯曲):怎么知道对象的属性是否存在(或规定)? [英] actionscript (flex): how to know whether a property of object exists (or defined)?

查看:103
本文介绍了动作(弯曲):怎么知道对象的属性是否存在(或规定)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是一个Java开发谁试图Flex的。这里是我的问题:

我的行为动作的对象作为HashMap的,但是当对象不具有的属性它给了异常:没有这样的变量。

在这里,我希望它给了,而不是让我异常空。所以,你知道是否有一种方法来处理它,即检查该属性被定义为对象。

跟踪(OBJ [2008-02])//给出了异常

解决方案

使用的东西沿行

 如果(myObject.hasOwnProperty(propertyName的))
 

要检查,如果该属性存在。

编辑:也看看这里

I am a Java developer who tries Flex. Here is my problem:

I behave actionScript objects as hashmap but when the object do not have the property it gives exception: No such variable.

Here I expect it gave me null, instead of giving exception. So do you know is there a way to handle it, namely check if the property is defined for object.

trace( obj["2008-02"] ) // gives exception

解决方案

Use something along the lines of

if (myObject.hasOwnProperty("propertyName"))

to check if the property exists.

Edit: Also take a look here.

这篇关于动作(弯曲):怎么知道对象的属性是否存在(或规定)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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