[英]Using a Formatter for the Currencies in SAPUI5
我想構建自己的格式化程序來顯示不同貨幣的金額。
有人可能猜到我使用了這個我已經知道的解決方案:
<t:template>
<Text text="{
parts: [
{path: 'amount'},
{path: 'currency'}
],
type:'sap.ui.model.type.Currency',
formatOptions: {
currencyCode: false
}
}"
</t:template>
這個解決方案的問題是我已經在一個單獨的列中顯示了貨幣,如果我使用這個解決方案,它看起來很丑......
所以我嘗試了這個:
<t:template>
<Text text="{parts: [
{path: 'amount'},
{path: 'currency'}
],
formatter : '.formatter.currency'}"
/>
</t:template>
我的格式化程序功能如下所示:
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 參考,因為它們是這樣說的:
如果您打算不顯示貨幣符號或代碼,因為您已經在其他地方顯示了它,您可以簡單地將showMeasure
設置為false
,例如:
<Text xmlns:core="sap.ui.core"
core:require="{ CurrencyType: 'sap/ui/model/type/Currency' }"
text="{
parts: [
'amount',
'currency'
],
type: 'CurrencyType',
formatOptions: {
showMeasure: false
}
}"
/>
不顯示貨幣代碼/符號是標准貨幣類型的一個特征。 你不需要擴展它。
注意:在 OData V4 的情況下,需要類型sap/ui/model /odata /type/Currency
。
如果要使用自定義格式化程序,可以這樣定義:
currency: function(amount, currency) {
var oCurrency = new sap.ui.model.type.Currency({
showMeasure: false
});
return oCurrency.formatValue([amount,curreny], "string");
}
但我建議在您的用例中使用 jpenninkhof 的解決方案
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.