gpt4 book ai didi

data-binding - SAPUI5:在 Controller 中检索模型对象

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

我有一个使用 OData 服务(在 manifest.json 中声明)的主从应用程序。

在细节 Controller 中,我通过以下方式将模型绑定(bind)到 View (此方法附加到路由器对象)。

_onObjectMatched: function(oEvent) {
this.getView().bindElement({
path: "/ContractCompSet('" + oEvent.getParameter("arguments").id + "')",
model: "contracts"
});
}

如何从此 Controller 中访问实际绑定(bind)的模型对象?

我得到的最接近(但似乎有点太复杂)如下
var path = this.getView().getElementBinding('contracts').sPath.substring(1);
var model = this.getView().getModel('contracts').oData[path];

最佳答案

好吧,您的方法并不遥远,并且确实与hirses几乎相同。

关键是绑定(bind)不包含“仅”绑定(bind)的模型对象。它包含有关模型、“绑定(bind)对象”的路径和上下文的信息。这些可以从绑定(bind)中检索。要访问“绑定(bind)对象”,您基本上有两个可用的路径。

从绑定(bind)中获取模型和路径并通过模型访问“绑定(bind)对象”:(这是你和hirse概述的)

var path = this.getView().getElementBinding('contracts').sPath;
var boundObject = this.getView().getModel('contracts').getProperty(path);

或者获取上下文和路径并以这种方式访问​​“绑定(bind)对象”:
var context = this.getView().getElementBinding('contracts').oContext;
var boundObject = context.getProperty(context.getPath());

在没有对此做太多研究的情况下,我更喜欢第二种选择。它似乎更符合上下文绑定(bind)的意图。

关于data-binding - SAPUI5:在 Controller 中检索模型对象,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32114263/

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