在 SAPUI5 中为货币使用格式化程序 [英] Using a Formatter for the Currencies in SAPUI5
问题描述
我想构建自己的格式化程序,以按不同货币显示金额.
I want to build my own formattor for displaying the amount as it should in the different currencies.
有人可能猜到我使用了这个我已经知道的解决方案:
One could guess I use this solution I already know:
<t:template>
<Text text="{
parts: [
{path: 'amount'},
{path: 'currency'}
],
type:'sap.ui.model.type.Currency',
formatOptions: {
currencyCode: false
}
}"
</t:template>
这个解决方案的问题是我已经在一个单独的列中显示了货币,如果我使用这个解决方案,它看起来很丑......
the problem with this solution is I already show the currency in a seperate column and if I go with this solution it looks pretty ugly....
所以我尝试了这个:
<t:template>
<Text text="{parts: [
{path: 'amount'},
{path: 'currency'}
],
formatter : '.formatter.currency'}"
/>
</t:template>
我的格式化程序函数如下所示:
and my formatter function looks like this:
currency: function(amount, currency) {
var change = [];
change.push(amount);
change.push(currency);
var sInternalType = "";
var amount1 = new sap.ui.model.type.Currency();
amount1.formatValue(change, sInternalType);
return amount1;
}
在这里,我猜我做错了一些事情,因为英语不是我的第一语言,我可能会认为我没有正确理解 API 参考,正如他们所说的那样:
Here I would guess I do something completely wrong, as English is not my first language I would probably assume I didnt understood the API References right, as they is stated this:
- formatValue(vValue, sInternalType): 任意
- 将包含金额和货币代码的给定数组格式化为字符串类型的输出值.Currency 类型不支持除 'string' 之外的其他内部类型.如果已为此类型定义了源格式,则 formatValue 也接受字符串值作为输入,该值将使用源格式解析为数组.如果 aValues 未定义或为 null,则返回 null.
- 参数:
- {array|string} vValue 要格式化的值数组或字符串值
- {string} sInternalType 目标类型
- 返回:
- {any} 格式化输出值
推荐答案
如果您打算不显示货币符号或代码,因为您已经在其他地方显示了它,您可以简单地将 showMeasure
设置为false
,例如:
If it is your intention not to show the currency symbol or code because you already show it elsewhere, you could simply set showMeasure
to false
, e.g.:
<Text xmlns:core="sap.ui.core"
core:require="{ CurrencyType: 'sap/ui/model/type/Currency' }"
text="{
parts: [
'amount',
'currency'
],
type: 'CurrencyType',
formatOptions: {
showMeasure: false
}
}"
/>
不显示货币代码/符号是标准货币类型的一项功能.您不需要扩展它.
Not showing the currency code/symbol is a feature of the standard Currency type. You don't need to extend it.
注意:对于 OData V4,需要类型 sap/ui/model/odata/type/Currency
.
Note: In case of OData V4, require the type sap/ui/model/odata/type/Currency
instead.
这篇关于在 SAPUI5 中为货币使用格式化程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!