我已经制定了计算总价的功能,但它似乎有效。该函数用于从数组收集中获取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个fielddata(名称产品,数量和价格)的arraycollection。在函数中,我想从数组收集中提取数据“数量”和数据“价格”,以便我计算“总价”。
目前我写的功能不起作用。我没有收到任何数据。
答案 0 :(得分:2)
total+=
而不是total=+
。您在运算符中有语法错误。
答案 1 :(得分: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;
}
答案 2 :(得分: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:你的跟踪输出是什么? (请&#34;调试&#34;,不要运行,以获得控制台输出)