SAPUI5 OData Binding not refreshing on route navigation

家住魔仙堡 提交于 2019-12-11 18:54:20

问题


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"
        });
    }

回答1:


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
        }
   }


来源:https://stackoverflow.com/questions/47923296/sapui5-odata-binding-not-refreshing-on-route-navigation

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!