Flex的 - 使用对象的属性名变量 [英] Flex - Use Variables for Object Attribute Names
本文介绍了Flex的 - 使用对象的属性名变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何使用变量访问对象的属性?
How do you use variables to access Object attributes?
假设我有一个对象声明如下,
Suppose I have an Object declared as follows,
var obj:Object = new Object;
obj.Name = "MyName";
obj.Age = "10";
如何,我会做这样的事,
How would i do something like this,
var fieldName:String = "Name";
var fieldAge:String = "Age";
var Name_Age:String = obj.fieldName + " ," + obj.fieldAge;
在code以上对待字段名和fieldAge作为属性名称本身。 欲处理的相同的变量,并且映射与变量作为对象属性名称相关联的值。
The code above treats 'fieldName' and 'fieldAge' as attribute name itself. I want to treat the same as a variable, and map the value associated with the variable as the Object attribute name.
推荐答案
只需使用方括号是这样的:
Just use square brackets like this:
var age:String = obj[fieldAge];
这篇关于Flex的 - 使用对象的属性名变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文