簡體   English   中英

在UI5中使用格式化程序功能后,視圖未呈現

[英]View is not Rendering after using formatter function in UI5

我正在為日期使用String類型的格式化程序功能。 我想在驗證后以yyyy/mm/dd格式顯示它,說如果值是"Unavailable"它應該顯示Blank [View is rendering]。

如果沒有,我應該以YYYY/MM/DD格式顯示。 因此,我對“時間”值進行了切片,並在調試器中返回了我期望的值,但視圖未呈現。

其他格式化程序功能正在運行。 使用切片功能后出現問題。

視圖

<Text text="{ path:'FORMULATIONDATE', formatter:'.getFormulation'}" wrapping="false" />

控制者

getFormulation: function(FORMULATIONDATE) {
  debugger;
  FORMULATIONDATE = FORMULATIONDATE.slice(0, 10);
  return (FORMULATIONDATE === "TimeUnavailable") ? null : FORMULATIONDATE;
}

考慮到FORMULATIONDATE是服務中的日期對象。

解決方案1:使用模型類型

<Text text="{path: 'FORMULATIONDATE', type: 'sap.ui.model.type.DateTime', 
      formatOptions: {pattern:'yyyy/mm/dd', UTC: true}}" /> <!--update your format -->

解決方案2:使用格式化程序

XML視圖

<Text text="{path: 'FORMULATIONDATE', formatter: 'formatter.formatDate'}" />

Formatter.js

jQuery.sap.require("sap.ui.core.format.DateFormat");
formatter = {
    formatDate: function(FORMULATIONDATE) {
        var dateFormat = sap.ui.core.format.DateFormat.getDateInstance({pattern : "dd.MM.YYYY"});//this is the default format
        if (FORMULATIONDATE == null) {  
            dateFormat = sap.ui.core.format.DateFormat.getDateInstance({pattern : "dd.MM.YYYY"});//update your format           
        } 
        var sFormatDate = dateFormat.format(FORMULATIONDATE);   
        return sFormatDate;
    }
}

注意:如果FORMULATIONDATE不是日期對象,則使用new Date(FORMULATIONDATE)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM