为什么Flex的ArrayCollection的Contain方法查看内存引用? [英] Why does Flex's ArrayCollection's Contain method look at memory reference?
问题描述
ArrayCollection
使用 .contains()
时,它总是会查看内存引用。它似乎没有看到 .equals()
方法或 .toString()
方法或任何可覆盖的方法。相反,我需要每次遍历 ArrayCollection
,并检查每个单独的项目,直到找到我要找的项目。 有谁知道为什么Flex / ActionScript是这样做的?为什么不提供一种方法让人们按照他们想要的方式使用 contains()
方法?
您可以通过让对象实现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屋!