将dateTime对象绑定到Text控件时,日期将以当前应用程序语言打印出来。它的风格可以通过“短”,“中”和“长”的风格属性的影响。如何在没有时区的情况下使用样式为“long”的DateTime?
我想使用长版本,而它加载了一个语言环境依赖模式,该模式以适当的方式呈现日期时间对象,除了最后的时区信息。
我当然可以使用自定义模式,但这会排除本地依赖项,因为它会覆盖样式属性。
我的想法是实现它: 我有自定义的DateTimeText控件,为我处理一些东西,另外,我想添加一个格式化程序,获取由控件生成的显示字符串(或从何处)最后10个字符(这是时区信息)
我努力得到这个工作,但我不知道如何从控制中获取输出字符串来操纵它。有没有一种方法(可能是一个更清洁的,然后我的想法)来得到它的工作?
DateTimeText控制
sap.ui.define(["sap/m/Text", "sap/ui/model/type/DateTime"], function (Text, DateTime) {
"use strict";
var DateTimeText = Text.extend("com.ui.common.DateTimeText", {
metadata : {
properties :
{
style : {type : "string", group : "Data", defaultValue : "long"}
}
},
renderer : "sap.m.TextRenderer",
onBeforeRendering : function() {
if(!this._bInitialized) {
var oTextBinding = this.getBindingInfo("text");
var sStyle = this.getStyle();
oTextBinding.parts[0].type = new DateTime({style: sStyle});
oTextBinding.binding.fnFormatter = this.formatLongDate(oTextBinding.binding.oValue);
this.bindProperty("text", oTextBinding);
this._bInitialized = true;
}
},
formatLongDate : function(oDate) {
console.log(oDate);
var s = oDate.slice(0,-10);
return s;
}
});
return DateTimeText;
}, true);
不添加格式化
oTextBinding.binding.fnFormatter = this.formatLongDate(oTextBinding.binding.oValue);
它显示的日期风格 “长”。但添加了格式化,当我得到这个错误:
Uncaught TypeError: oDate.slice is not a function
at formatLongDate (DateTimeText.js:27)
at f.onBeforeRendering (DateTimeText.js:19)
at f.a._handleEvent (sap-ui-core.js:959)
at t (sap-ui-core.js:1087)
at constructor.R.renderControl (sap-ui-core.js:1089)
at I.renderControl (sap-ui-core.js:457)
at Object.G.render (GridRenderer.js:6)
at constructor.R.renderControl (sap-ui-core.js:1089)
at I.renderControl (sap-ui-core.js:457)
at d.a.renderContainers (ResponsiveGridLayoutRenderer.js:6)
没有一些示例代码,这真的很难说。 – evolutionxbox
我添加了我的DateTimeControl的代码 –