为什么Flex的ArrayCollection的Contain方法查看内存引用? [英] Why does Flex's ArrayCollection's Contain method look at memory reference?

查看:263
本文介绍了为什么Flex的ArrayCollection的Contain方法查看内存引用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Flex中对 ArrayCollection 使用 .contains()时,它总是会查看内存引用。它似乎没有看到 .equals()方法或 .toString()方法或任何可覆盖的方法。相反,我需要每次遍历 ArrayCollection ,并检查每个单独的项目,直到找到我要找的项目。



有谁知道为什么Flex / ActionScript是这样做的?为什么不提供一种方法让人们按照他们想要的方式使用 contains()方法?

解决方案好吧,看起来ArrayCollection实际上并不直接看内存,而只是作为最后的手段。它将尝试为对象查找唯一标识(UID)。如果UID不存在,它将使用UIDUtil.as为其创建一个。



您可以通过让对象实现IUID接口并为对象提供您自己的UID。 ArrayCollection将查看您提供的UID。


When using .contains() on an ArrayCollection in Flex, it will always look at the memory reference. It does not appear to look at an .equals() method or .toString() method or anything overridable. Instead, I need to loop through the ArrayCollection every time and check each individual item until I find what I'm looking for.

Does anyone know why Flex/ActionScript was made this way? Why not provide a way from people to use the contains() method the way they want?

解决方案

Well, it seems like the ArrayCollection doesn't actually look directly at memory, but only as a last resort. It will attempt to find a Unique ID (UID) for the object. If the UID doesn't exist, it will create one for it using the UIDUtil.as.

You can get around this whole default UID stuff by having your object implement the IUID interface and providing your own UID for the object. The ArrayCollection will look at the UID you provide it.

这篇关于为什么Flex的ArrayCollection的Contain方法查看内存引用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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