每当我使用 F5 刷新页面时,都会收到错误:
在调试中,我看到 totalRtn 有值,所以它转到其他 - 当控制转到 sap.m.MessageBox.confirm 时 - 我收到一个错误,说"未捕获的类型错误:无法读取未定义的属性'确认'">
if (totalRtn <= 0) {
sap.m.MessageToast.show("Cannot return 0 quantity");
} else {
sap.m.MessageBox.confirm("You are returning total of " + totalRtn + " items from this order", {
actions: [sap.m.MessageBox.Action.YES, sap.m.MessageBox.Action.NO],
styleClass: "messageBoxError",
onClose: function(oAction) {
if (oAction === sap.m.MessageBox.Action.YES) {
ServiceUtils.createEntry(this, oEntry, sEntity, sURL).done(function(data) {
var jsonModel = new JSONModel(data);
var returnNumber = jsonModel.getProperty("/data/SalesDocument");
sap.m.MessageToast.show("Return " + returnNumber + " is created successfully");
vc.getOwnerComponent().getRouter().navTo("stockrooms", {
"companyId": vc.companyId
}, false);
}).fail(function(error) {
sap.m.MessageToast.show("Error in return processing");
});
} else {
sap.m.MessageToast.show("Return not confirmed");
}
}
});
你需要加载模块"sap.m.MessageBox">
试试这个:
jQuery.sap.require("sap.m.MessageBox");
if (totalRtn <= 0) {
sap.m.MessageToast.show("Cannot return 0 quantity");
} else {
sap.m.MessageBox.confirm("You are returning total of " + totalRtn + " items from this order", {
actions: [sap.m.MessageBox.Action.YES, sap.m.MessageBox.Action.NO],
styleClass: "messageBoxError",
onClose: function(oAction) {
if (oAction === sap.m.MessageBox.Action.YES) {
ServiceUtils.createEntry(this, oEntry, sEntity, sURL).done(function(data) {
var jsonModel = new JSONModel(data);
var returnNumber = jsonModel.getProperty("/data/SalesDocument");
sap.m.MessageToast.show("Return " + returnNumber + " is created successfully");
vc.getOwnerComponent().getRouter().navTo("stockrooms", {
"companyId": vc.companyId
}, false);
}).fail(function(error) {
sap.m.MessageToast.show("Error in return processing");
});
} else {
sap.m.MessageToast.show("Return not confirmed");
}
}
});
问候!
是的,MessageBox 是一个静态类,一个 sap.ui.require("sap/m/MessageBox"(; 语句必须先显式执行,然后才能使用该类。
根据 Jorg 在评论中提到的内容,最新的最佳实践描述了,如果在某些情况下只使用控件,则应仅在需要时加载库。这将提高初始加载性能。
在您的示例中,只需在totalRtn
大于 0 时加载sap.m.MessageBox
库。因此,我建议对您提供的代码进行以下更改:
else {
sap.ui.require(["sap/m/MessageBox"], function(oMessageBox) {
oMessageBox.confirm("You are returning total of " + totalRtn + " items from this order", {
actions: [sap.m.MessageBox.Action.YES, sap.m.MessageBox.Action.NO],
styleClass: "messageBoxError",
onClose: function(oAction) {
if (oAction === sap.m.MessageBox.Action.YES) {
ServiceUtils.createEntry(this, oEntry, sEntity, sURL).done(
function(data) {
var jsonModel = new JSONModel(data);
var returnNumber = jsonModel.getProperty("/data/SalesDocument");
sap.m.MessageToast.show("Return " + returnNumber + " is created successfully");
vc.getOwnerComponent().getRouter()
.navTo("stockrooms",
{ "companyId": vc.companyId },
false
);
}).fail(function(error) {
sap.m.MessageToast.show("Error in return processing");
});
} else {
sap.m.MessageToast.show("Return not confirmed");
}
}
});
}.bind(this));
...