在 1.5.2.3 定义绑定(bind)路径 OpenUI5 demokit 部分:
A context exists either for each entry of the aggregation in case of aggregation binding or can be set explicitly for a control by using the setBindingContext method.
在 1.5.3.3 元素绑定(bind) OpenUI5 demokit 部分:
Element binding allows to bind elements to a specific object in the model data, which will create a binding context and allow relative binding within the control and all of its children.
在我看来,这两种技术实际上做了同样的事情。它们都为控件创建绑定(bind)上下文,以便包含控件的绑定(bind)将相对于它进行解析。但是他们之间有什么区别呢?它们中的任何一个会在什么情况下发挥作用?
设置绑定(bind)上下文 在以下代码中不起作用:https://jsbin.com/bigope/edit?html,output
但是,如果我更改 oPanel.setBindingContext("/nameinfo"); 至 oPanel.bindElement("/nameinfo"); ,它有效,为什么?
最佳答案
setBindingContext
要求您传递这样的上下文:
oPanel.setBindingContext(new sap.ui.model.Context(oModel, "/nameinfo"));
这两者之间的区别是概念上的。
绑定(bind)上下文用作该控件或其子项中所有绑定(bind)(针对该模型)的父上下文。它仅包含对使用的模型、路径的(一部分)和可选的另一个父上下文的引用。它在创建相对绑定(bind)时使用。
bindElement
另一方面,方法的行为与其他所有 bind* 方法一样。它创建一个允许更改事件、数据绑定(bind)等的绑定(bind)(在本例中为
ContextBinding
)。另外创建的
ContextBinding
也用作其他绑定(bind)的 BindingContext,就像使用 setBindingContext 添加的 Context 一样。一点也不令人困惑,对吧;)?
阅读 ManagedObject 的代码可能会帮助您更好地了解内部结构。 (绑定(bind)对象 = 绑定(bind)元素)
关于sapui5 - setBindingContext() 的用法和与元素绑定(bind)的区别是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31283011/