Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
453 views
in Technique[技术] by (71.8m points)

SAPUI5 OData Binding not refreshing on route navigation

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

After suffering with a similar problem for a while, I finally found the culprit - in the model settings in manifest.json, I changed the "defaultBindingMode" from "OneTime" to "OneWay".

    "models": {
         ...
         ...

        "": {
            "type": "sap.ui.model.odata.v2.ODataModel",
            "settings": {
                "defaultOperationMode": "Server",
                "defaultBindingMode": "OneWay",
                "defaultCountMode": "Request"
            },
            "dataSource": "yourdatasource",
            "preload": true
        }
   }

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

1.4m articles

1.4m replys

5 comments

57.0k users

...