在我的blHandleDelButtonPressed()
函数中,我正在对单个/多个选定的表行执行删除条目请求。请求完成后(在success
/之后error
)我想在 Dialog 内显示一个消息视图(sap.m.MessageView
就像这里的这个一样https://sapui5.hana.ondemand.com/#/entity/sap.m.MessageView/sample/sap .m.sample.MessageViewInsideDialog)。
问题是请求DONE的时候,弹出Message View,但是里面没有数据↓↓↓
这是示例代码:
displayMsgDialog: function(oDialog) {
oDialog.open();
},
blHandleDelButtonPressed: function(oEvent) {
var oModel = this.getOwnerComponent().getModel();
var oTable = this.getView().byId("bookingsList");
var oSelectedItems = oTable.getSelectedItems();
var aBookingRemovals = [];
oTable.setBusy(true);
oSelectedItems.forEach(function(selectedItem) {
var oBooking = selectedItem.getBindingContext();
var sPath = oBooking.getPath(),
sBookId = oBooking.getProperty("bookid"),
sPassName = oBooking.getProperty("PASSNAME"),
sCustomId = oBooking.getProperty("CUSTOMID");
oModel.remove(sPath, {
success: function(oData, response) {
aBookingRemovals.push({
type: "Success",
title: "Booking " + sBookId + " successfully removed",
subtitle: "Book ID: " + sBookId + " | Passager: " + sPassName + " | ID: " + sCustomId
});
},
error: function() {
aBookingRemovals.push({
type: "Error",
title: "Booking " + selectedItem.getBindingContext().getProperty("bookid") + " wasn't removed",
subtitle: "Book ID: " + sBookId + " | Passager: " + sPassName + " | ID: " + sCustomId
});
}
});
});
oTable.setBusy(false);
var oBookingRemovalsTpl = new sap.m.MessageItem({
type: "{type}",
title: "{title}",
subtitle: "{subtitle}"
});
var oModelBookingRemovals = new JSONModel();
oModelBookingRemovals.setData(aBookingRemovals);
this.oBookingRemovalsView = new sap.m.MessageView({
showDetailsPageHeader: false,
items: {
path: "/",
template: oBookingRemovalsTpl
}
});
this.oBookingRemovalsView.setModel(oModelBookingRemovals, "BookingRemovals");
this.oBookingRemovalsDialog = new sap.m.Dialog({
resizable: true,
content: this.oBookingRemovalsView,
state: 'Information',
beginButton: new sap.m.Button({
press: function () {
this.getParent().close();
oTable.removeSelections();
aBookingRemovals = [];
},
text: "Close"
}),
customHeader: new sap.m.Bar({
contentMiddle: [
new sap.m.Text({ text: "We tried to remove selected bookings"})
]
}),
contentHeight: "300px",
contentWidth: "500px",
verticalScrolling: false
});
// Displaying the final Message View inside Dialog
this.displayMsgDialog(this.oBookingRemovalsDialog);
}
浏览器的控制台不显示任何错误/警告。
奇怪的事情:
在我选择了 3 个随机行并执行该blHandleDelButtonPressed()
函数后,我detail.oBookingRemovalsView.getModel("BookingRemovals").getData()
在 Chrome 的控制台中调用,这给了我这个 ↓↓↓ (如您所见,来自选定行的数据被插入到BookingRemovals
模型中并绑定到window.detail.oBookingRemovalsView
)
> detail.oBookingRemovalsView.getModel("BookingRemovals").getData()
(3) [{…}, {…}, {…}, {…}, {…}]
1: {type: "Error", title: "Booking 00000001 wasn't removed", subtitle: "Book ID: 00000001 | Passager: Benjamin Waldmann | ID: 00004113"}
2: {type: "Error", title: "Booking 00000002 wasn't removed", subtitle: "Book ID: 00000002 | Passager: Adam Gutenberg | ID: 00002720"}
3: {type: "Error", title: "Booking 00000005 wasn't removed", subtitle: "Book ID: 00000005 | Passager: Juan Martin | ID: 00003740"}
length: 5
__proto__: Array(0)
但是当我打电话时detail.oBookingRemovalsView.getItems()
,我得到了一个空数组↓↓↓</p>
> detail.oBookingRemovalsView.getItems()
[]
length: 0
__proto__: Array(0)
哪里有问题?