SAPUI5 OData绑定在路径导航上未刷新 [英] SAPUI5 OData Binding not refreshing on route navigation

查看:249
本文介绍了SAPUI5 OData绑定在路径导航上未刷新的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

对于一个SAPUI5应用程序,我创建了一个具有实体查询"的OData服务. 该服务本身可以正常工作.

For a SAPUI5 app I created an OData service having an entity "Enquiries". The service itself works fine.

为了在该服务之上构建第一个SAPUI5应用程序,我使用了演练以获取基础知识: https://sapui5.hana.ondemand.com/#/topic/2366345a94f64ec1a80f9d9ce50a59ef

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

现在,如果我用一个服务替换Northwind服务并将其绑定为模型查询",则除了一件事之外,其他所有功能都可以正常工作. 单击列表项("enquiry/>"查询)时,它会通过数据绑定正确地加载对象的详细信息-但仅一次! 回到主视图并选择另一个列表项时,它将再次打开详细信息视图,但仍显示单击的第一个列表项的详细信息.

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.

通过单击主视图中的列表项打开新的URL/路径时,似乎未刷新详细信息视图.但是在使用Northwind OData服务的环境中的演练"示例中,它可以100%正常工作.

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.

有人有线索吗?

一些编码...

列表视图:

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

列表控制器-单击列表项时触发事件onPress:

[..]
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)
        });
    } 
[..]

详细信息视图:

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

详细信息控制器-在初始化时触发事件:

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

推荐答案

在经历了类似的问题一段时间之后,我终于找到了罪魁祸首-在manifest.json的模型设置中,我将"defaultBindingMode"从"OneTime"到"OneWay".

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

这篇关于SAPUI5 OData绑定在路径导航上未刷新的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆