2017-08-21 6 views

答えて

0

DatePickerにロケールの直接プロパティはありません。しかし、これを克服するために、やや不器用なトリックがあり、残念ながらそれは、sap.ui.core.format.DateFormatのインスタンスを格納プライベート属性「_oDisplayFormat」を、使用しています。これを実証するスニペットは以下の通りです:

<!DOCTYPE html> 
 
<html> 
 
\t <head> 
 
\t \t <meta name="description" content="UI5 DatePicker with non-default locale"/> 
 
\t <meta http-equiv='X-UA-Compatible' content='IE=edge' /> 
 
\t <meta http-equiv='Content-Type' content='text/html;charset=UTF-8'/> 
 
\t 
 
     
 
     <title>UI5 DatePicker Example with different Locales</title> 
 
\t 
 
\t <script id='sap-ui-bootstrap' type='text/javascript' 
 
\t \t src='https://openui5.hana.ondemand.com/resources/sap-ui-core.js' 
 
\t \t data-sap-ui-theme='sap_bluecrystal' 
 
\t \t data-sap-ui-libs='sap.m,sap.ui.core'> 
 
    </script> 
 

 
\t <script> 
 
     var oVBox = new sap.m.VBox({ width: "50%"});  
 
     
 
      var oFrenchFormat; 
 
      var oEnglishFormat; 
 
      
 
      var oDatePicker = new sap.m.DatePicker({ dateFormat: "long" }); 
 
     oDatePicker.setValue(new Date()); 
 

 
     oVBox.addItem(oDatePicker); 
 
      oVBox.addItem(new sap.m.Button({ 
 
      text: "Set French locale", 
 
      press: function(oEvent) { 
 
       if (!oFrenchFormat) { 
 
       oFrenchFormat = sap.ui.core.format.DateFormat.getDateInstance({ style: "full"}, new sap.ui.core.Locale("fr_FR")); 
 
       } 
 
       var oDate = oDatePicker.getValue(); 
 
       oDatePicker._oDisplayFormat = oFrenchFormat; 
 
       oDatePicker.setDisplayFormat("long"); 
 
       oDatePicker.setValue(oDate); 
 
      } 
 
      })); 
 
      
 
      oVBox.addItem(new sap.m.Button({ 
 
      text: "Set US locale", 
 
      press: function(oEvent) { 
 
       if (!oEnglishFormat) { 
 
       oEnglishFormat = sap.ui.core.format.DateFormat.getDateInstance({ style: "full"}, new sap.ui.core.Locale("en_US")); 
 
       } 
 
       var oDate = oDatePicker.getValue(); 
 
       oDatePicker._oDisplayFormat = oEnglishFormat; 
 
       oDatePicker.setDisplayFormat("long"); 
 
       oDatePicker.setValue(oDate); 
 
      } 
 
      })); 
 

 
     oVBox.placeAt("content"); 
 
\t </script> 
 
\t </head> 
 
\t <body class="sapUiBody" id="content"> 
 
\t </body> 
 
</html>

関連する問題