For a SAPUI5 app I created an OData service having an entity "Enquiries".
The service itself works fine.
In order to build a first SAPUI5 app on top of that service, I took the Walkthrough to get the basics: https://sapui5.hana.ondemand.com/#/topic/2366345a94f64ec1a80f9d9ce50a59ef
Now if I replace the Northwind Service by my one service and binding it as model "enquiry", it all works fine except one thing.
When clicking on an list item ("enquiry/>Enquiries"), it loads the details of that object through data binding correctly - but only once!
When going back to master view and selecting another list item, it opens the detail view again, but still shows the details of the first list item clicked.
It seems like the detail view is not refreshed when a new URL/path is opened by clicking on a list item in the master view. But it works 100% in the Walkthrough example in my environment using the Northwind OData service.
Does anybody have a clue?
Some coding...
list view:
<mvc:View
controllerName="sap.ui.demo.wt.controller.InvoiceList"
xmlns="sap.m"
xmlns:mvc="sap.ui.core.mvc">
<List
class="sapUiResponsiveMargin"
width="auto"
items="{path : 'enquiry>/Enquiries'}">
<items>
<ObjectListItem
title="{enquiry>CompanyName}"
type="Navigation"
press="onPress">
</ObjectListItem>
</items>
</List>
</mvc:View>
list controller - fires event onPress when clicking on a list item:
[..]
onPress: function (oEvent) {
var oItem = oEvent.getSource();
var oRouter = sap.ui.core.UIComponent.getRouterFor(this);
oRouter.navTo("detail", {
enquiryPath: oItem.getBindingContext("enquiry").getPath().substr(1)
});
}
[..]
detail view:
<mvc:View
controllerName="sap.ui.demo.wt.controller.Detail"
xmlns="sap.m"
xmlns:mvc="sap.ui.core.mvc">
<Page
title="{i18n>detailPageTitle}">
<ObjectHeader
intro="{enquiry>EnquiryID}"/>
</Page>
detail controller - fires event on init:
onInit: function () {
var oRouter = sap.ui.core.UIComponent.getRouterFor(this);
oRouter.getRoute("detail").attachPatternMatched(this._onObjectMatched, this);
},
_onObjectMatched: function (oEvent) {
this.getView().bindElement({
path: "/" + oEvent.getParameter("arguments").enquiryPath,
model: "enquiry"
});
}
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…