UI5 格式化程序不工作
UI5 formatter not working
我无法让这个简单的格式化程序正常工作,我不知道出了什么问题。
ap.ui.jsview("splitapp.DetailPage", {
getControllerName: function() {
return "splitapp.DetailPage";
},
createContent: function(oController) {
jQuery.sap.require("sap.ui.core.format.DateFormat");
var oType = new sap.ui.model.type.DateTime({
source: {
pattern: "yyyy-MM-dd HH:mm:ss Z"
}
});
var oDateFormat = sap.ui.core.format.DateFormat.getInstance({
pattern: "MM/dd/yyyy"
});
oLayout.createRow(new sap.ui.commons.TextView({
text: "Fecha de apertura",
design: sap.ui.commons.TextViewDesign.Bold
}),
new sap.ui.commons.TextView({
text: {
path: "ticketSelected>/fechaApertura",
type: oType,
formatter: function(d) {
return oDateFormat.format(new Date(d))
}
}
})
);
}
});
唯一的问题是您在格式化程序中的 d
值将是 ""
空字符串..
formatter: function(d) {
var date = new Date(); //or any default value you want to set
if (d) {
date = new Date(d);
}
return oDateFormat.format(date);
}
我无法让这个简单的格式化程序正常工作,我不知道出了什么问题。
ap.ui.jsview("splitapp.DetailPage", {
getControllerName: function() {
return "splitapp.DetailPage";
},
createContent: function(oController) {
jQuery.sap.require("sap.ui.core.format.DateFormat");
var oType = new sap.ui.model.type.DateTime({
source: {
pattern: "yyyy-MM-dd HH:mm:ss Z"
}
});
var oDateFormat = sap.ui.core.format.DateFormat.getInstance({
pattern: "MM/dd/yyyy"
});
oLayout.createRow(new sap.ui.commons.TextView({
text: "Fecha de apertura",
design: sap.ui.commons.TextViewDesign.Bold
}),
new sap.ui.commons.TextView({
text: {
path: "ticketSelected>/fechaApertura",
type: oType,
formatter: function(d) {
return oDateFormat.format(new Date(d))
}
}
})
);
}
});
唯一的问题是您在格式化程序中的 d
值将是 ""
空字符串..
formatter: function(d) {
var date = new Date(); //or any default value you want to set
if (d) {
date = new Date(d);
}
return oDateFormat.format(date);
}