UserName}" /> onItemPress: function(oEvent) { var oUserContext -6ren">
gpt4 book ai didi

OData V4 更改未反射(reflect)在其他绑定(bind)中

转载 作者:行者123 更新时间:2023-12-04 02:22:18 25 4
gpt4 key购买 nike

我创建了一个 UI5 主从页面:

掌握

<List items="{som>/Users}">
<StandardListItem
type="Navigation"
press="onItemPress"
title="{som>UserName}"
/>
</List>

onItemPress: function(oEvent) {
var oUserContext = oEvent.getSource().getBindingContext("som");
var oUser = oUserContext.getObject();
this.getRouter().navTo("userDetails", {userId: oUser.Id});
}

细节

onInit: function () {
var route = this.getRouter().getRoute("userDetails");
route.attachPatternMatched(this._onObjectMatched, this);
},

_onObjectMatched: function (oEvent) {
var sUserId = oEvent.getParameter("arguments").userId;
this.getView().bindElement({
path: "som>/Users('"+sUserId+"')",
model: "som"
});
},

reload: function() {
this.getView().getModel("som").refresh();
},

<fLayout:SimpleForm id="userForm">
<Button text="reload" press="reload"/>
<Label text="{i18n>settings.user.id}"/>
<Input editable="false" value="{som>Id}"/>
<Label text="{i18n>settings.user.username}"/>
<Input value="{som>UserName}"/>
<Label text="{i18n>settings.user.email}"/>
<Input value="{som>Email}"/>
<Label text="{i18n>settings.user.firstname}"/>
<Input value="{som>FirstName}"/>
<Label text="{i18n>settings.user.lastname}"/>
<Input value="{som>LastName}"/>
</fLayout:SimpleForm>

一切正常。但是当我在详细 View 中更改用户时,它正在更新但不在主视图中!使用 reload 方法,我可以手动刷新它。但是如何在更改后自动触发呢?我可以在 SimpleForm 上绑定(bind)更改事件吗?

最佳答案

https://embed.plnkr.co/qatUyq/?show=preview:%3Fsap-ui-xx-componentPreload%3Doff
https://embed.plnkr.co/qatUyq/
使用 OData V4 TripPin 服务的最小示例
请记住 v4.ODataModel仍在进行中。 同步模式必须为 "None" 目前。

synchronizationMode

Controls synchronization between different bindings which refer to the same data for the case data changes in one binding. Must be set to 'None' which means bindings are not synchronized at all [...].


更新:根据 UI5 roadmap (需要 SAP 社区帐户),数据绑定(bind)同步支持“计划在 2021 年第二季度”。
因此,应用程序本身必须识别相关绑定(bind)并手动刷新它们。为了提高效率,我们可以通过批处理组 ID 将此类 GET 请求与更新请求一起发送,即 v2.ODataModel。自动执行(除非 refreshAfterChange 被禁用)。
在上面的示例中,我使用了以下设置和 API:
  • $$updateGroupId: "myGroupId"用于上下文绑定(bind)(详细信息页面)。
  • 用户按下提交后,调用 refresh("myGroupId") 从列表绑定(bind)(主列表)。
  • 最后 submitBatch("myGroupId") .

  • 如果我们然后检查请求负载,我们可以 see that the PATCH and GET requests are bundled一起。因此,主列表同时被刷新。

    问答
  • v4.ODataModel中的默认绑定(bind)模式是什么?
  • It's "TwoWay" (除非 sharedRequests 已启用) - UI 会更改模型数据,反之亦然。当更改为 不是 存储在批处理队列中,相应的请求立即发送到后端。

  • 我如何知道我是否使用批处理模式?
  • v4 中的几乎所有绑定(bind)以及模型本身都支持参数 $$groupId用于读取,并且某些绑定(bind)支持 $$updateGroupId用于更新请求。
  • 如果 ID 设置为 "$direct" ,对应的请求直接发送,不分批。这些请求更容易诊断,cacheable通过浏览器。
  • 如果 ID 是自定义字符串(如上例),则相应的请求将由 API submitBatch 显式发送.
  • 如果没有定义这样的 ID,默认值设置为 "$auto" ,这意味着默认情况下,在重新呈现所有相关控件后,请求会自动批量发送。

  • 查看文档主题 Batch Control .

  • 即使这两个请求(GET 和 PATCH)捆绑为一个,应用程序如何确保在更新完成后始终应用刷新列表?
  • 该模型已经解决了这个问题:

    The OData V4 model automatically puts all non-GET requests into a single change set, which is located at the beginning of a batch request. All GET requests are put after it.



  • 为什么我可以调用submitBatch没有像我对 v2.ODataModel 那样事先将组添加到“延迟组”中?
  • V4 简化了批处理组的处理:

    Application groups are by default deferred; there is no need to set or get deferred groups. You just need the submitBatch method on the model to control execution of the batch. [doc]



  • 模型通常支持 requestSent 等事件。和 requestCompleted .为什么我不能在 v4.ODataModel 中使用它们?
  • 只是设计不支持它。见 Unsupported Superclass Methods and Events .


  • 希望我让一些事情更清楚。 UI5 中有关 OData V4 的最新文档可在以下位置找到: https://openui5nightly.hana.ondemand.com/topic/5de13cf4dd1f4a3480f7e2eaaee3f5b8

    关于OData V4 更改未反射(reflect)在其他绑定(bind)中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49274818/

    25 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com