0

我制作了一个计算总价的函数,但它似乎没有用。该函数用于从 arraycollection 中获取 2 个数据字段,这两个数据字段是我希望能够计算的。

        [Bindable]public var total:Number=0;
        private function gridClickEvent(event:ListEvent):void {             
            var quantity:Number=acCart[event.columnIndex].quantity;
            var price:Number=acCart[event.columnIndex].price;
            total += quantity * price;

        }

我计算的总数将显示在标签中

<s:Label id="prijs" text="{total}" />

我想要的是计算总价。我有一个包含 3 个字段数据(名称产品、数量和价格)的数组集合。在一个函数中,我想从数组集合中提取数据“数量”和数据“价格”,以便计算“总价格”。

目前我写的功能不起作用。我没有收到任何数据。

4

3 回答 3

2

total+=不是total=+。_ 运算符中有语法错误。

于 2012-12-23T17:07:23.900 回答
2

做一些调试:

private function gridClickEvent(event:ListEvent):void {

    //see if getting expected values 
    trace(event.rowIndex);
    trace(acCart[event.rowIndex].quantity);
    trace(acCart[event.rowIndex].price);

    var quantity:Number=parseFloat(acCart[event.rowIndex].quantity);
    var price:Number=parseFloat(acCart[event.rowIndex].price);
    total += quantity * price;
}
于 2012-12-23T17:44:08.733 回答
0

为什么不只是

private function gridClickEvent(event:ListEvent):void {
    .... // your math here

    trace("old total = "+ total);
    total += quantity * price;
    trace("new total = "+ total);

    // forget about binding and manually set the property
    prijs.text = total.toString();
}

绑定有时在 flex 中很疯狂,即使你/我完全理解 Binding 的机制,它仍然有可能绑定不工作或者值被设置 N 次而不是一次(有几个 MVC 框架的情况) )。

出于这个原因,我讨厌绑定,并且我在使用它时有所保留。

PS:你的跟踪输出是什么?(请“调试”,不要运行,以获得控制台输出)

于 2013-05-01T18:00:49.600 回答