2016-11-17 122 views
0

使用SAPUI5 xml視圖,我想將一個格式化程序添加到輸入字段。根據用戶輸入的內容(數字),我希望看到附加的值爲%。如何將輸入字段格式化爲百分比值?

so if userinput value = "99" ---> "99%" or ".5" ---> "50%" 

查看數據類型,我不確定是否有一個'out of box'解決方案將輸入值格式化爲百分比。任何想法如何實現?

<Input 
    id="percentGrowth" 
    type="Text" 
    value="{path:'inputModel>/myPath', type:'sap.ui.model.type.Float', contraints: {maximum : 1}}" > 
</Input> 

回答

1

你應該使用一個格式化 Formatter sapui5

例如

<Input 
    id="percentGrowth" 
    type="Text" 
    value="{path:'inputModel>/myPath', 
    type:'sap.ui.model.type.Float', 
    contraints: {maximum : 1}, 
    formatter:'.myFormatter'}" > 
</Input> 

然後在你的控制器中添加功能

myController.prototype.myFormatter(value){ 
    return value + "%"; 
} 

進一步的細節,你有一個例子此鏈接至SDN