Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/date/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Date 从SAPUI5表中的ODataModel格式化日期_Date_Format_Sapui5 - Fatal编程技术网

Date 从SAPUI5表中的ODataModel格式化日期

Date 从SAPUI5表中的ODataModel格式化日期,date,format,sapui5,Date,Format,Sapui5,我有一个从OData模型填充的SAPUI5表。其中一列是我想格式化的日期/时间字段,但我不知道如何在SUI5中实现 这就是我现在正在做的: var tableModel = new sap.ui.model.odata.ODataModel("..."); var table = new sap.ui.table.DataTable(); table.setModel(tableModel); table.addColumn(new sap.ui.table.Column({ label

我有一个从OData模型填充的SAPUI5表。其中一列是我想格式化的日期/时间字段,但我不知道如何在SUI5中实现

这就是我现在正在做的:

var tableModel = new sap.ui.model.odata.ODataModel("...");
var table = new sap.ui.table.DataTable();
table.setModel(tableModel);
table.addColumn(new sap.ui.table.Column({
    label: new sap.ui.commons.Label({text: "Date"}),
    template: new sap.ui.commons.TextView().bindProperty("text", "DATE"),
    sortProperty: "DATE",
    filterProperty: "DATE"
}));
以下是输出的前几行(我的浏览器语言是德语):

我所要做的就是将日期和时间格式更改为,例如,mm/dd/yyyy hh:mm

我做了一些搜索,下面的问题正是我的问题-但有一个公认的答案,要么我不理解,要么实际上没有解决问题:


我意识到这可能是一个微不足道的问题,我只是错过了如何轻松做到这一点,或者它是在一个官方教程处理。在这种情况下,请在评论中指出它,我将删除此问题。

使用格式化程序功能:

var tableModel = new sap.ui.model.odata.ODataModel("...");
var table = new sap.ui.table.DataTable();
table.setModel(tableModel);
table.addColumn(new sap.ui.table.Column({
    label: new sap.ui.commons.Label({text: "Date"}),
    template: new sap.ui.commons.TextView({
        text : { 
            path : 'DATE',
            formatter : function(value){
                return /* TODO: some format logic */;
            }
        }
    }),
    sortProperty: "DATE",
    filterProperty: "DATE"
}));

使用格式化程序函数是非常灵活的,但是如果您不需要编写自己的格式逻辑来寻找更简单的东西,则可以考虑使用<代码>类型属性,而不是使用<代码>格式化程序< /代码>:

template: new sap.ui.commons.TextView().bindProperty("text", {
  path: "OrderDate",
  type: new sap.ui.model.type.Date({pattern: "MM/dd/yyyy hh:mm"})
})

我还添加了如何使用格式化程序函数格式化数字

 <template> = new sap.ui.commons.TextField().bindProperty("<value>",{
          path: "<GROSSVALUE>",
          type: new sap.ui.model.type.Integer({
              maxIntegerDigits: 10,
              minFractionDigits: 2,
              maxFractionDigits: 2,
              groupingEnabled: true,
              groupingSeparator: ",",
              decimalSeparator: "."
            })});     
=new sap.ui.commons.TextField().bindProperty(“{
路径:“”,
类型:new sap.ui.model.type.Integer({
最大整数位数:10,
最小分数位数:2,
maxFractionDigits:2,
groupingEnabled:是的,
分组分隔符:“,”,
小数分隔符:“.”
})});     

标准模型格式化程序也值得考虑:和

XML示例(始终使用XML;)



由于使用UI5通常是关于为应用程序应用标准视图的对话,因此使用标准格式可能是一个有用的想法。

Ah!有道理。我没有捕获“path”参数。谢谢你,尼古拉!谢谢你。这两种方法对我现在所做的工作都很有用,因为我的表中有一个简单的日期列和一个更复杂的自定义格式列。如果您希望从XML视图实现这一点,您还可以通过以下方式实现:
感谢Mitch我一直在寻找它。可能是
template: new sap.ui.commons.TextView().bindProperty("text", {
  path: "DATE",
  type: new sap.ui.model.type.DateTime,
  formatOptions: { style: "medium" }
})
<Text text="{path : 'runDateTime', 
             type : 'sap.ui.model.type.DateTime',
             formatOptions: { style : 'medium'}}" />