如何在填充 AdvancedDataGrid 之前将 XML 数据转换为数字

发布于 2024-11-16 02:39:38 字数 951 浏览 4 评论 0原文

我导入 XML 数据以填充 AdvancedDataGrid(使用 Flex 4.5)。
此 ADG 正确填充了数据,列显示了正确的信息等等。

我想使用以下方法总结此 ADG

<mx:SummaryRow summaryPlacement="group">
    <mx:SummaryField2 dataField="Cost" label="amount" summaryOperation="SUM">
</mx:SummaryRow>

但有一个问题!事实上,“成本”数据作为“字符串”导入,这就是为什么我无法进行求和...结果我只是得到了一个很好的 0! 我想将这些数据转换为数字,以便可以进行加法处理。我认为这种转换必须在填写 ADG 之前完成。

我已经尝试实现一个自定义的summaryOperation,但很不幸...

public function calculateSummary(data:Object, field:SummaryField2, rowData:Object):void
{
    var dataField:String = field.dataField;
    var value:Number = Number(rowData[dataField]);
    Alert.show(rowData[dataField]);
    if (!data.hasOwnProperty(dataField))
        data[dataField] = value ;
    else
        data[dataField] += value;   
}

警报总是显示一条无效消息,数据不会传输到这个函数我认为

还有一件事:用户可以在XML中动态插入新数据并且插入必须更新 SUM 结果。

有人可以帮助我吗?我会继续搜索,如果找到什么,我会发布它:D

谢谢!

I import XML data in order to fill an AdvancedDataGrid (using Flex 4.5).
This ADG is correctly filled with the data, columns display the right information etc. etc.

I would like to summarize this ADG using

<mx:SummaryRow summaryPlacement="group">
    <mx:SummaryField2 dataField="Cost" label="amount" summaryOperation="SUM">
</mx:SummaryRow>

But there is a problem! Indeed, the 'Cost' data are imported as 'Strings' and that is why I cannot do the SUM... I just get a nice 0 as a result!
I would like to convert these data into Numbers, so that the addition can be processed. This conversion has to be done before filling the ADG I think.

I already tried to implement a custom summaryOperation but was unlucky...

public function calculateSummary(data:Object, field:SummaryField2, rowData:Object):void
{
    var dataField:String = field.dataField;
    var value:Number = Number(rowData[dataField]);
    Alert.show(rowData[dataField]);
    if (!data.hasOwnProperty(dataField))
        data[dataField] = value ;
    else
        data[dataField] += value;   
}

The Alert always displays a void message, the data are not transmitted to this function I think

There is another thing: the user can insert new data in the XML dynamically and that insertion has to update the SUM result.

Could anybody help me? I will go on searching and if I find something, I would post it :D

Thank you!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(2

不必在意 2024-11-23 02:39:38

您可以将字符串转换为数字,执行如下操作:

var myNewNumber : Number = Number(stringValue);

我不确定您到底想在代码中执行此操作。您绝对可以将 XML 转换为对象数组,然后使用该数组作为 dataProvider。我怀疑您也可以将其作为计算总数的过程的一部分。

You can convert astring to a number doing something like this:

var myNewNumber : Number = Number(stringValue);

Where exactly you want to do that in relation to your code, I'm not sure. You could definitely convert your XML into an array of objects, and then use that array as your dataProvider. I suspect you could also do it as part of the process to calculate the total.

纵性 2024-11-23 02:39:38

如果您使用 XML,请不要忘记使用“@”来标识属性 (@Cost)。

<mx:SummaryRow summaryPlacement="group">
    <mx:SummaryField2 dataField="@Cost" label="amount" summaryOperation="SUM">
</mx:SummaryRow>

您不需要将字符串转换为数字,框架已经在内部执行此操作。

If you are working with XML don't forget to use the '@' to identify the attibute (@Cost).

<mx:SummaryRow summaryPlacement="group">
    <mx:SummaryField2 dataField="@Cost" label="amount" summaryOperation="SUM">
</mx:SummaryRow>

You don't need to convert Strings to Numbers, the framework is already doing it internally.

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