私はテンプレートアプローチを追求せずに新しいSAPUI5アプリケーションを構築しています。私が構築しているのは、2つのフィールドとボタンが付いた小さなフォームです。 AHHhh ... "ボタン"。SAPUI5:データをODataサービスにプッシュする際に読み込みダイアログボックスを表示するにはどうすればよいですか?
ボタンについてはどうですか?ボタンは次のコードがあります。それに
<Button text="OK" width="100%" id="__button1" press="insertIntoOData"/>
を、私はボタンを押すと、 insertIntoOData関数が呼び出されることを期待しています。そして、何を推測する!それは!
素晴らしい! ODataのモデルは、レコードの挿入を処理しながら -
は、しかし、問題は insertIntoODataで、私はそれが(チェックこのlinkフラグメントを使用して構築された)ダイアログを表示したいということです。残念ながら、私はダイアログを表示させることができませんでした。 のinsertIntoOData関数は同期的に呼び出され、関数が完了するまでダイアログは表示されません。
ODataモデルで挿入処理が完了すると、応答が処理され、 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関数呼び出し?
をあなたの要求が非常に高速に処理されている場合、それは本当にダイアログを表示する意味がありませんか?ビュー(およびコントロール)には、あなたのケースではより適切な「ビジー」プロパティがあります。 – Marc
こんにちは@Valak、odataリクエストを非同期にしてください。リクエストの作成はデフォルトでは同期的なので、ブラウザは応答が到着するのを待ってから先に進む。したがって、応答が戻ってくるとポップアップが開きますが、次の行にはポップアップを閉じます。したがって、2番目のポップアップが表示されます。 TL; DR:JSはシングルスレッド言語です。oData.createのasyncプロパティを使用してチェックしてください。 –
@Marc:リクエストが非常に遅いので、ロードすることが必要です。ビューのビジーなプロパティは何もしません。 – Valac