Actionscript 3 如何在Actionscript中获取对象中的属性列表?

Actionscript 3 如何在Actionscript中获取对象中的属性列表?,actionscript-3,flex3,filterfunction,Actionscript 3,Flex3,Filterfunction,我有一个数据提供程序和一个分配给我的数据提供程序的数组的filterfunction 当数据提供程序(item.data)传递给filterfunction时,我如何获取数据提供程序(item.data)每行中的属性列表 例如,如果我的对象包含: 反对 名字 电子邮件 地址 然后我希望,在我的filterfunction中能够查看姓名、电子邮件和地址。不幸的是,我不知道这些属性将是什么 有什么想法吗?如果它是一个动态对象,我相信你可以这样做: var obj:Object; // I'm

我有一个数据提供程序和一个分配给我的数据提供程序的数组的filterfunction

当数据提供程序(item.data)传递给filterfunction时,我如何获取数据提供程序(item.data)每行中的属性列表

例如,如果我的对象包含:

  • 反对
    • 名字
    • 电子邮件
    • 地址
然后我希望,在我的filterfunction中能够查看姓名、电子邮件和地址。不幸的是,我不知道这些属性将是什么


有什么想法吗?

如果它是一个动态对象,我相信你可以这样做:

var obj:Object; // I'm assuming this is your object

for(var id:String in obj) {
  var value:Object = obj[id];

  trace(id + " = " + value);
}
obj = m:email@ra..., r:true

AS2就是这样做的,我相信这在AS3中仍然适用于动态对象。我认为它将显示的属性在非动态对象上更为有限。

您可以使用for。。在循环中获取属性名称,或为每个。。在循环中获取属性值


for( var o : * in object){
    trace( o + " = " + object[o] );
}
/************* OR ******************/
for each( var o : * in object ){
    trace( "object has property: " + o );
}

仅适用于动态对象。对于类型化对象,您需要使用某种反射来获取属性名称(例如)


/安德烈。

您可能正在寻找

ObjectUtil.getClassInfo(object) 
,见:

请注意,其中存在一个bug,导致它将XML视为非动态数据类型。 有关错误的更多信息,请参见:
bugs.adobe.com/jira/browse/SDK-17712还将为您提供对象的属性列表。

对我来说只有以下几点有用:

// this method will work for retrieving properties of a *non-dynamic* (typed) object

// @return - all object properties
public function getProperties(_obj : *) : Array
{
        var _description : XML = describeType(_obj);
        var _properties : Array = new Array();
        for each (var prop:XML in _description.accessor)
        {
                var _property : Object = new Object();
                _property.name = String(prop.@name);
                _property.type = String(simple_type(prop.@type));
                _property.access = String(prop.@access);
                _property.declaredBy = String(prop.@declaredBy);
                try
                {
                   _property.value = _obj[_property.name];
                }
                catch (e : Error)
                {
                   _property.value = "";
                }
                _properties.push(_property)
        }
        _properties.sortOn("name");
        return _properties;
}

// better format for object class information
private function simple_type(_type : String) : String
{
        var lastIndex : int = _type.lastIndexOf("::");
        _type = lastIndex > 0 ? _type.substr(lastIndex + 2) : _type;
        return _type;
}
trace('obj = '+getProperties(obj));

        public static function getProperties(obj:*):String  {
            var p:*;
            var res:String = '';
            var val:String;
            var prop:String;
            for (p in obj) {
                prop = String(p);
                if (prop && prop!=='' && prop!==' ') {
                    val = String(obj[p]);
                    if (val.length>10) val = val.substr(0,10)+'...';
                    res += prop+':'+val+', ';
                }
            }
            res = res.substr(0, res.length-2);
            return res;
        }
你会得到这样的结果:

var obj:Object; // I'm assuming this is your object

for(var id:String in obj) {
  var value:Object = obj[id];

  trace(id + " = " + value);
}
obj = m:email@ra..., r:true

这也会对您有所帮助。
1.for循环-将根据索引工作
2.对于每个递归调用,最大长度
3.for in-用于读取属性值

     for( var obj : String in objectData ) //here objectData is your object
     {
        trace( "Object Name Is : " + obj );
        var data : Object = objectData[obj]; //here we get the object value by using the property name
        trace( "Value Is : " + data ); //Converts object to string
     }

完美的效果很好。好几天来我一直在想这个问题。非常感谢!G-Man+1即使是AS3也不再有eval了,像这样的东西使它成为动态的。“我认为它将显示的属性在非动态对象上更加有限。”这一个对我很有用。我在一个对象中从我的web api反序列化JSON,这里列出的其他方法不起作用(我尝试了所有其他方法)。谢谢简单_类型是如何声明的?