我在不追求任何模板方法的情况下构建新的SAPUI5应用程序。我正在构建的只是一个带有两个字段和一个按钮的小表格。 AHHhh ...“按钮”。
那按钮呢?该按钮具有以下代码:
<Button text="OK" width="100%" id="__button1" press="insertIntoOData"/>
这样,我希望当我按下按钮时,将调用insertIntoOData函数。你猜怎么着!?它是!
太棒了!
但是问题是,在OData模型处理记录的插入时,我希望在insertIntoOData中显示一个对话框(由片段构建-选中此link)。不幸的是,我没有设法显示该对话框。看起来insertIntoOData函数是被同步调用的,直到该函数完成后才会显示对话框。
当OData Model完成插入操作后,将处理响应,并且仅显示一会儿对话框,因为您可能会在以下insertIntoOData代码中注意到,导航将重定向到母版(主)页面。
insertIntoOData: function(evt) {
/*
* to prevent namespace issues, reserve 'this' into 'that',
* so the ajax will know who to call inside its scope
*/
var that = this;
//declare the dialog
if (!that._dialog) {
that._dialog = sap.ui.xmlfragment("valac.view.requestloading", null);
that.getView().addDependent(that._dialog);
}
// open dialog
jQuery.sap.syncStyleClass("sapUiSizeCompact", that.getView(), that._dialog);
that._dialog.open();
// get the csrf token from the service url
var csrfToken = this.getCSRFToken("/valacDestination/sap/c4c/odata/v1/c4codata/ValacObjectCollection");
// get the values from the 'form'
var name_var = this.byId("tSubjectInput").getValue();
var description_var = this.byId("tDescriptionArea").getValue();
// create the entry that will be sent with the request
var oEntry = {};
// the description list
oEntry.requestDescription = [];
// the description item that goes inside the list
var entryOfRequestDescription = {};
entryOfRequestDescription.Text = description_var;
oEntry.requestDescription.push(entryOfRequestDescription);
// name is a complex object that needs to be built. Content and language.
oEntry.Name = {};
oEntry.Name.content = name_var;
oEntry.Name.languageCode = "EN";
// fetch the model schema
var oModel = new sap.ui.model.odata.ODataModel("/valacDestination/sap/c4c/odata/v1/c4codata/");
sap.ui.getCore().setModel(oModel);
/* create the entry into the model schema via ajax
* return to the master page if there's a success response
* put a message on the master page.
*/
oModel.create('/ValacObjectCollection', oEntry, null, function(response){
that._dialog.close();
sap.ui.core.UIComponent.getRouterFor(that).navTo("master");
sap.m.MessageToast.show("Object Persisted!", {
duration: 30000000
});
},function(){
that._dialog.close();
sap.m.MessageToast.show("ERROR!", {
duration: 30000000
});
});
}
我的问题是:如何在insertIntoOData结束或调用oModel.create函数之前显示对话框?
最佳答案
当您输入insertIntoOData方法时。
致电服务之前
that._dialog.setBusy(true);
获得服务响应后(成功或错误无关紧要)设置为
that._dialog.setBusy(false);