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

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

问题描述

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

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.

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

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?

推荐答案

好吧,似乎 ArrayCollection 实际上并不直接查看内存,而只是作为最后的手段.它将尝试为对象查找唯一 ID (UID).如果 UID 不存在,它将使用 UIDUtil.as 为它创建一个.

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.

您可以通过让您的对象实现 IUID 接口并为该对象提供您自己的 UID 来解决整个默认 UID 问题.ArrayCollection 将查看您提供的 UID.

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天全站免登陆