gpt4 book ai didi

javascript - 首先打开“无数据” View ,然后打开包含 Fiori 中数据的详细信息页面

转载 作者:行者123 更新时间:2023-12-01 00:07:27 25 4
gpt4 key购买 nike

我正在开发一个主详细信息应用程序,其中如果服务 URL 不返回数据,则应打开一个名为“NoData”的 View 。但实际发生的情况是,首先打开“NoData” View ,然后显示包含数据的详细信息页面。我不知道为什么以及如何首先出现“NoData”页面。以下是我的母版页代码:

Controller .js:

        onInit: function () {

this.router = sap.ui.core.UIComponent.getRouterFor(this);
this._custTemp = this.getView().byId("listItemTemp").clone();
this.refreshFlag = true; // Flag to get new data or not for customers


this.totalModel = sap.ui.getCore().getModel("totalModel");
this.getView().setModel(this.totalModel, "totalModel");

this.oDataModel = sap.ui.getCore().getModel("DataModel");
this.getView().setModel(this.oDataModel, "DataModel");


this.oInitialLoadFinishedDeferred = jQuery.Deferred();
var oEventBus = sap.ui.getCore().getEventBus();

this.getView().byId("listId").attachEvent("updateFinished", function () {
this.oInitialLoadFinishedDeferred.resolve();
oEventBus.publish("MasterPage", "InitialLoadFinished", {
oListItem: this.getView().byId("listId").getItems()[0]
});
if (!sap.ui.Device.system.phone) {
this._getFirstItem();
}
}, this);

this.functionData = [];
},
waitForInitialListLoading: function (fnToExecute) {
jQuery.when(this.oInitialLoadFinishedDeferred).then(jQuery.proxy(fnToExecute, this));
},

_getFirstItem: function () {
sap.ui.core.BusyIndicator.show();
this.waitForInitialListLoading(function () {
// On the empty hash select the first item
var list = this.getView().byId("listId");
var selectedItem = list.getItems()[0];
if (selectedItem) {
list.setSelectedItem(selectedItem, true);
var data = list.getBinding("items").getContexts()[0];
sap.ui.getCore().getModel("detailModel").setData(data.getObject());

this.router.navTo('DetailPage', {
QueryNo: data.EICNO
});
sap.ui.core.BusyIndicator.hide();
} else {
this.router.navTo('NoData');
}
}, this);
},

onBeforeRendering: function () {
this._fnGetData();
},

_fnGetData: function (oEvent) {

var that = this;
this.getView().setModel(this.totalModel, "totalModel");

if (this.refreshFlag === true) {
sap.ui.core.BusyIndicator.show(0);

$.ajax({
url: "/sap/opu/odata/sap/ZHR_V_CARE_SRV/EmpQueryInitSet('10002001')?$expand=QueryLoginToQueryList/QueryToLog",
method: "GET",
dataType: "json",
success: function (data) {
that.getView().getModel("totalModel").setData(data.d.QueryLoginToQueryList);

that.refreshFlag = false;
sap.ui.core.BusyIndicator.hide();
that.statusList();

},
error: function (err) {
sap.ui.core.BusyIndicator.hide();
MessageBox.information(err.responseText + "Please try again");
}
});

}

}

最佳答案

totalModel 是一个 json 模型,对吗?您将在应用加载时收到两个 updateFinished 事件。第一个在列表控件呈现并完成绑定(bind)后触发(当模型没有数据时),第二个在 $.ajax 调用将数据更新到 totalModel 后触发。

我认为您可以通过将 NoData 导航移至 $.ajax 调用的“成功”和“错误”回调来解决此问题。这样做可能会涵盖其他用例,例如如果您使用 URL 导航参数,并且用户将 URL 中的实体 ID 更改为某个随机数,则它会导航到您的 NoData 页面。

关于javascript - 首先打开“无数据” View ,然后打开包含 Fiori 中数据的详细信息页面,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60282076/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com