如何获取 Actionscript 中对象的属性列表?
我有一个数据提供程序和一个分配给我的数据提供程序的数组的过滤函数。
当数据提供程序 (item.data) 传递给过滤器函数时,如何获取数据提供程序 (item.data) 每一行中的属性列表?
例如,如果我的对象包含:
- 对象
- 姓名
- 电子邮件
- 地址
然后我希望在我的过滤函数中能够查看姓名、电子邮件和地址。 不幸的是,我事先不知道这些属性是什么。
有任何想法吗?
I have a dataprovider and a filterfunction for my array that's assigned to my dataprovider.
How can I get a list of the properties that are in each row of the dataprovider (item.data) as it gets passed to the filterfunction?
For instance, if my object contained:
- Object
- name
- address
Then I would want, in my filterfunction to be able to look at name, email and address. Unfortunately, I don't know what these properties will be before hand.
Any ideas?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(8)
flash.utils .describeType(value:*)
还将为您提供对象的属性列表。flash.utils.describeType(value:*)
will also give you a list of properties on an object.for-in 仅适用于动态对象。 对于类型化对象,您需要使用某种反射来获取属性名称(例如 http: //www.as3commons.org/as3-commons-reflect/index.html)
/安德烈。
for-in works for dynamic objects only. For typed objects you need to use some kind of reflection to get property names (e.g. http://www.as3commons.org/as3-commons-reflect/index.html)
/Andrei.
您可能正在寻找
,请参阅:
http ://livedocs.adobe.com/flex/3/langref/mx/utils/ObjectUtil.html#getClassInfo%28%29
请注意,其中存在一个错误,导致它将 XML 视为非- 动态数据类型。
有关该错误的更多信息,请参见:
bugs.adobe.com/jira/browse/SDK-17712
You are probably looking for
,see:
http://livedocs.adobe.com/flex/3/langref/mx/utils/ObjectUtil.html#getClassInfo%28%29
Be aware that there is a bug in it which causes it to treat XML as a non-dynamic data type.
More on the bug in:
bugs.adobe.com/jira/browse/SDK-17712
对我来说只有这个有用:
你会得到这样的东西:
for me was useful only this:
and you get something like this:
您可以使用 for .. in 循环来获取属性名称,或者使用 for every .. in 循环来获取属性值...
you can use a for .. in loop to get the properties names, or a for each .. in loop to get the property values ...
这也会帮助你..
1. for 循环 - 将基于索引工作
2. 对于每个 - 递归调用直到长度
3. for in——用于读取属性值
This also will help you..
1. for Loop - Will work based on index
2. for each - recursive call upto the length
3. for in - used to read the property values
如果它是一个动态对象,我相信你可以这样做:
这就是 AS2 中的做法,并且我相信这仍然适用于 AS3 中的动态对象。 我认为它将显示的属性更多地局限于非动态对象。
If it's a dynamic object I believe you can just do something like this:
That's how it's done in AS2, and I believe that still works for dynamic objects in AS3. I think the properties that it will show is more limited on non-dynamic objects.