如何在flex中动态设置对象的属性或字段
我有一个包含名称的数组,
var myArray:Array=new Array("name1","name2","name3");
现在我想通过迭代数组来使用数组值作为对象属性 我的意思是我希望对象具有 name1,name2,name3 作为属性,
var myObject:Object=new object();
for(var i:int=0; i<myArray.length; i++){
myObject[myArray[i]]="something";
}
但这并没有给我所需的结果, 它将对象属性设置为 myArray[i] 即,在这种情况下,我在方括号内给出的任何内容都被视为字符串。我希望输出为,
myObject[name1]="something"
myObject[name2]="something"
myObject[name3]="something"
但它给出的输出为 有
myObject[myArray[i]]="something"
任何想法如何做到这一点?
I have an array containing names lets say,
var myArray:Array=new Array("name1","name2","name3");
Now I want to use the array values as the object properties by iterating through the array
I meant I want the object to have name1,name2,name3 as the properties,
var myObject:Object=new object();
for(var i:int=0; i<myArray.length; i++){
myObject[myArray[i]]="something";
}
but this does not give me the required result,
it sets the object property as myArray[i] i.e, whatever I give inside the square braces is taken as a string in this case.I want the output to be,
myObject[name1]="something"
myObject[name2]="something"
myObject[name3]="something"
but instead it gives the output as
myObject[myArray[i]]="something"
Any ideas how to do this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
不确定我是否完全理解,但我认为您已经实现了目标。
在调试器中,我看到:
这不是您想要的吗?
我相信你所说的是等价的。
Not sure I fully understand, but I think you've accomplished your goal.
In the debugger, I see:
Was this not what you want?
I believe what you've stated is equivalent.