构建数组时可以调用函数吗?

发布于 2024-09-14 06:31:57 字数 766 浏览 7 评论 0原文

在 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

蘸点软妹酱 2024-09-21 06:31:57

你说你的函数只被调用一次。然而在您的代码中您只显式调用它一次。我很难看到你的问题。在 ActionScript 中,您可以创建对象数组,其中属性值可以来自函数的返回值。

编辑更改您的代码来执行此操作:

public function gridBuilder(myArray:Array):void {
    var i:uint; 
    var dGArray:Array = [];

    for (i=0; i<myArray.length; i++) {
        dgArray.push({Name: myArray[i].name,
                      Type: 'A:',
                      Score: myArray[i].score,
                      Rank: myArray[i].rank,
                      Grade:myFunction(myArray[i].rank,myArray[i].max_rank)});
        dgArray.push({Name: myArray[i].name,
                      Type: 'B:',
                      Score: myArray[i].score,
                      Rank: myArray[i].rank});
    }
    dgAC = new ArrayCollection(dGArray);
}

原始代码的问题是您在每次迭代时不断重置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:

public function gridBuilder(myArray:Array):void {
    var i:uint; 
    var dGArray:Array = [];

    for (i=0; i<myArray.length; i++) {
        dgArray.push({Name: myArray[i].name,
                      Type: 'A:',
                      Score: myArray[i].score,
                      Rank: myArray[i].rank,
                      Grade:myFunction(myArray[i].rank,myArray[i].max_rank)});
        dgArray.push({Name: myArray[i].name,
                      Type: 'B:',
                      Score: myArray[i].score,
                      Rank: myArray[i].rank});
    }
    dgAC = new ArrayCollection(dGArray);
}

The problem with your original code was that you kept resetting your dGArray on each iteration.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文