2016-06-27 15 views
0

我想要構建自己的格式化程序以顯示不同貨幣的金額。在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參考權,因爲他們陳述的:

  • formatValue(VVALUE, sInternalType):any
  • 將包含金額和貨幣代碼的給定數組格式化爲字符串類型的輸出值。 「貨幣」類型不支持「串」之外的其他內部類型。如果已經爲此類型定義了源格式,則formatValue也會接受一個字符串值作爲輸入,該值將使用源格式解析爲數組。如果aValues未定義或爲null,則返回null。
  • 參數:
  • {陣列|串} VVALUE值或字符串值的陣列要被格式化
  • {串} sInternalType目標類型
  • 返回:
  • {任何}格式化的輸出值

回答

3

如果這是你的意圖不顯示貨幣符號或代碼,因爲你已經證明它在其他地方,你可以簡單地設置「showMeasure」爲假,例如:

text="{ 
    parts: [ 
     {path: 'amount'}, 
     {path: 'currency'} 
    ], 
    type: 'sap.ui.model.type.Currency', 
    formatOptions: { 
     showMeasure: false 
    } 
}" 

未顯示貨幣代碼/符號是標準貨幣類型的功能。你不需要擴展它。

+0

真棒謝謝你! – Nali