本文介绍了如何格式化"MM/yyyy"模式转换为与语言环境相关的“<月份名称>"/yyyy"在SAPUI5中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我从后端获取日期为数据格式"12/2019",并希望以"Dez/2019"格式进行转换,(德语为"Dez",英语为"Dec").有人知道吗?

I get dates from backend as data format "12/2019" and would like to convert in the format "Dez / 2019" ("Dez" in German, "Dec" in English). Has anyone an idea?

我的XML视图中的摘录:

Snippet from my XML view:

<cells>
  <Text text="{Period}" />
  <!-- ... -->
<cells>

期间是OData V2实体属性,其EDM类型为String.

Period is an OData V2 entity property and its EDM type is String.

推荐答案

尝试使用:

<Text text="{
  path: 'Period',
  type: 'sap.ui.model.type.Date',
  formatOptions: {
    pattern: 'MMM / yyyy',
    source: {
      pattern: 'MM/yyyy'
    }
  }
}" />

这是一个有效的演示(单击):

Here is a working demo (Click on ):

sap.ui.getCore().attachInit(() => sap.ui.require([
  "sap/ui/core/Fragment",
], Fragment => Fragment.load({
  definition: `<Text xmlns="sap.m"
    text="{
      value: '12/2019',
      type: 'sap.ui.model.type.Date',
      formatOptions: {
        pattern: 'MMM / yyyy',
        source: {
          pattern: 'MM/yyyy'
        }
      }
    }"
  />`
}).then(control => control.placeAt("content"))));
<script id="sap-ui-bootstrap"
  src="https://openui5.hana.ondemand.com/resources/sap-ui-core.js"
  data-sap-ui-libs="sap.ui.core,sap.m"
  data-sap-ui-theme="sap_fiori_3"
  data-sap-ui-async="true"
  data-sap-ui-compatversion="edge"
  data-sap-ui-xx-waitfortheme="init"
></script><body id="content" class="sapUiBody"></body>

由于 Period 的EDM类型为String,因此只需使用 sap.ui.model.type.Date 就足够了.但是,如果类型是 Edm.DateTime (通常用于表示OData V2中的日期值),则类型 sap.ui.model .odata .type.应该考虑日期时间 .

Since the EDM Type of Period is String, simply using sap.ui.model.type.Date should be sufficient in this case. If the Type is however Edm.DateTime, which is usually used to represent date values in OData V2, then the type sap.ui.model.odata.type.DateTime should be considered.

这篇关于如何格式化"MM/yyyy"模式转换为与语言环境相关的“&lt;月份名称&gt;"/yyyy"在SAPUI5中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-12 03:55