admin管理员组文章数量:1289543
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....
so I tried this one:
<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;
}
Here I would guess I do something pletely 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): any
- Format the given array containing amount and currency code to an output value of type string. Other internal types than 'string' are not supported by the Currency type. If an source format is has been defined for this type, the formatValue does also accept a string value as input, which will be parsed into an array using the source format. If aValues is not defined or null, null will be returned.
- Parameters:
- {array|string} vValue the array of values or string value to be formatted
- {string} sInternalType the target type
- Returns:
- {any} the formatted output value
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....
so I tried this one:
<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;
}
Here I would guess I do something pletely 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): any
- Format the given array containing amount and currency code to an output value of type string. Other internal types than 'string' are not supported by the Currency type. If an source format is has been defined for this type, the formatValue does also accept a string value as input, which will be parsed into an array using the source format. If aValues is not defined or null, null will be returned.
- Parameters:
- {array|string} vValue the array of values or string value to be formatted
- {string} sInternalType the target type
- Returns:
- {any} the formatted output value
2 Answers
Reset to default 6If 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.
Note: In case of OData V4, require the type sap/ui/model/odata/type/Currency
instead.
If you want to use an custom formatter, you can define it in this way:
currency: function(amount, currency) {
var oCurrency = new sap.ui.model.type.Currency({
showMeasure: false
});
return oCurrency.formatValue([amount,curreny], "string");
}
But I would remend to use the solution from jpenninkhof for your use case
本文标签: javascriptUsing a Formatter for the Currencies in SAPUI5Stack Overflow
版权声明:本文标题:javascript - Using a Formatter for the Currencies in SAPUI5 - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741470528a2380575.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论