简体   繁体   English

将 hasPendingChanges() 绑定到视图模型

[英]Bind hasPendingChanges() to View-Model

I want to use the hasPendingChanges() method from v2 ODataModel in my view.我想在我的视图中使用 v2 ODataModel 中的hasPendingChanges()方法。 Therefore I want to set a property named detailView>/pendingChnages in my view-model.因此,我想在我的视图模型中设置一个名为detailView>/pendingChnages的属性。 Is there a event in v2 ODataModel or in binding (element / context-binding) for every change to check the hasPendingChanges-method in v2 ODataModel? v2 ODataModel 或绑定(元素/上下文绑定)中是否存在用于检查 v2 ODataModel 中的 hasPendingChanges 方法的每次更改的事件?

Thanks in advance!提前致谢!

I Just found a solution for my requirement.我刚刚找到了满足我要求的解决方案。 I could remember a video I've watched recently: https://youtu.be/-bs-RBG7f5Q?t=2116我记得最近看过一个视频: https://youtu.be/-bs-RBG7f5Q?t=2116

For the solution I register a change-Event for a sap.ui.model.Binding .对于解决方案,我为sap.ui.model.Binding注册了一个 change-Event。

var oCtx = this.getView().getBindingContext();
var oBinding = new sap.ui.model.Binding(this.getView().getModel(), oCtx.getPath(), oCtx);
oBinding.attachChange(function(){
    this.getView().getModel("detailView").setProperty("/pendingChanges", this.getModel().hasPendingChanges());
}.bind(this));

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM