在创建模板之前,我为控制器上的一个表创建了一个模板,该表由一些获取oData的文本单元格组成,但也包括一个组合框和具有自己功能的复选框,这非常长。该模板最初位于XML端,但为了过滤正确的oData,必须将其移动到控制器端。
如何将该函数添加到复选框中?此外,我是否可以将日期/时间格式化为只显示月份,就像我在xml方面所做的那样?
var oTemplate = new sap.m.ColumnListItem({
cells: [
new sap.m.Text({
text: "{ID}"
}),
//this does not work
new sap.m.CheckBox({
select: function(){
this.estimatePercentageSelect();
}
}),
new sap.m.ComboBox({
items: [new sap.ui.core.ListItem("cMonth", {
text: currentMonthName,
key: currentMonthName
}),
new sap.ui.core.ListItem("month1", {
text: monthName1,
key: monthName1
}),
new sap.ui.core.ListItem("month2", {
text: monthName2,
key: monthName2
}),
new sap.ui.core.ListItem("month3", {
text: monthName3,
key: monthName3
})
]
}),
new sap.m.Text({
text: "{INSTALL}"
}),
//this formatting also does not work
new sap.m.Text({
text: "{DATE}"
/*,
type: "sap.ui.model.type.DateTime",
formatOptions: "{pattern: 'MMM'}" */
}),
new sap.m.Text({
text: "{DWN}"
}),
new sap.m.Text({
text: "{EST}"
}),
new sap.m.Text({
text: "{PLAN}"
})
]
});发布于 2018-01-23 05:10:29
下面是我对您的代码的反馈:
在这里,这个对象将引起问题,因为这个将引用您的控件(复选框),而不是您的控制器。
取而代之的是这样做:
new sap.m.CheckBox({
select: [
this.estimatePercentageSelect, this
]
}),在您的函数中,让对象进行检查。
estimatePercentageSelect : function(oEvent) {
var oSource = oEvent.getSource(); // your clicked checkbox
var oContext = oSource.getBindingContext().getObject(); // checkbox binding object/context
console.log(oContext);
}创建日期对象:
var oDateType = new sap.ui.model.type.Date({
source: {
pattern: "yyyymmdd"
},
style: "MMM"
});然后把它传递给你的控制:
new sap.m.Text({
text: {
path: "DATE",
type: oDateType
}
}),如果这对你有用的话请告诉我。很乐意改进代码。
https://stackoverflow.com/questions/48394379
复制相似问题