构建数组时可以调用函数吗?
在 Flex 3 中构建数组时可以调用函数吗?
public function gridBuilder(myArray:Array):void {
var i:uint;
for (i=0; i<myArray.length; i++){
dGArray = [
{Name: myArray[i].name, Type: 'A:', Score: myArray[i].score, Rank: myArray[i].rank, Grade:(myFunction(myArray[i].rank, myArray[i].max_rank))},
{Name: myArray[i].name, Type: 'B:', Score: myArray[i].score, Rank: myArray[i].rank }
]
}
dgAC = new ArrayCollection(dGArray);
}
MyArray 是远程调用数据库的结果。然后我准备要在 dataGrid 中使用的数组。我还想调用一个提供成绩的函数。不幸的是,我的函数似乎只被调用一次。构建数组时是否可以调用函数?请参阅“等级:”位。有什么问题吗?我该如何解决这个问题?
谢谢你!
-拉克斯米迪
Can I call a function when building an array in Flex 3?
public function gridBuilder(myArray:Array):void {
var i:uint;
for (i=0; i<myArray.length; i++){
dGArray = [
{Name: myArray[i].name, Type: 'A:', Score: myArray[i].score, Rank: myArray[i].rank, Grade:(myFunction(myArray[i].rank, myArray[i].max_rank))},
{Name: myArray[i].name, Type: 'B:', Score: myArray[i].score, Rank: myArray[i].rank }
]
}
dgAC = new ArrayCollection(dGArray);
}
MyArray is the result of a remote call to the database. I then prepare the array to be used in a dataGrid. I also want to call a function that provides a grade. Unfortunately, my function appears to be called only once. Is it possible to call a function when you're building an array? Please see the "Grade:" bit. What's the problem? How do I solve this problem?
Thank you!
-Laxmidi
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
你说你的函数只被调用一次。然而在您的代码中您只显式调用它一次。我很难看到你的问题。在 ActionScript 中,您可以创建对象数组,其中属性值可以来自函数的返回值。
编辑更改您的代码来执行此操作:
原始代码的问题是您在每次迭代时不断重置
dGArray
。You stated that your function was only called once. Yet in your code you are only explicitly calling it once. I am having trouble seeing your issue. In ActionScript, you can create an Array of objects, where attribute values can come from return values of functions.
EDIT Change your code to do this:
The problem with your original code was that you kept resetting your
dGArray
on each iteration.