Javascript ';无数据';首先打开获取视图,然后打开包含Fiori中数据的详细信息页面
我正在开发一个Master-Detail应用程序,如果服务URL不返回数据,那么应该打开一个名为“NoData”的视图。但实际情况是,首先打开“NoData”视图,然后显示包含数据的详细信息页面。我不知道为什么和如何“NoData”页面首先出现。以下是我的母版页代码: Controller.js:Javascript ';无数据';首先打开获取视图,然后打开包含Fiori中数据的详细信息页面,javascript,sapui5,sap-fiori,Javascript,Sapui5,Sap Fiori,我正在开发一个Master-Detail应用程序,如果服务URL不返回数据,那么应该打开一个名为“NoData”的视图。但实际情况是,首先打开“NoData”视图,然后显示包含数据的详细信息页面。我不知道为什么和如何“NoData”页面首先出现。以下是我的母版页代码: Controller.js: onInit: function () { this.router = sap.ui.core.UIComponent.getRouterFor(this);
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
事件。第一个是在呈现列表控件并完成绑定(当模型没有数据时)后触发的,第二个是在$.ajax调用将数据更新为totalModel
后触发的
我认为您可以通过将
NoData
导航移动到$.ajax调用的“成功”和“错误”回调来解决这个问题。这样做可能会涉及其他用例,例如,如果您使用URL导航参数,并且用户将URL中的实体ID更改为某个随机数,它将导航到您的NoData
页面。totalModel
是json模型,对吗?在应用程序加载时,您将获得两个updateFinished
事件。第一个是在呈现列表控件并完成绑定(当模型没有数据时)后触发的,第二个是在$.ajax调用将数据更新为totalModel
后触发的
我认为您可以通过将NoData
导航移动到$.ajax调用的“成功”和“错误”回调来解决这个问题。这样做可能涉及其他用例,例如,如果您正在使用URL导航参数,并且用户将URL中的实体ID更改为某个随机数,则它将导航到您的NoData
页面