What's the usage of setBindingContext() and the difference from element binding?

后端 未结 1 1417
广开言路
广开言路 2021-02-09 17:46

In the 1.5.2.3 Defining a Binding Path section of OpenUI5 demokit:

A context exists either for each entry of the aggregation in case of a

1条回答
  •  暖寄归人
    2021-02-09 18:24

    setBindingContext requires you to pass a Context like this:

    oPanel.setBindingContext(new sap.ui.model.Context(oModel, "/nameinfo"));
    

    The difference between those two is conceptual. The Binding Context is used as a parent context for all bindings (for that model) in that Control or its children. It only holds a reference to the used model, (a part of) the path and optional another parent context. It is used when creating relative bindings.

    The bindElement method on the other hand behaves like every other bind* method. It creates a binding (in this case, a ContextBinding) which allows change events, data binding, etc. Additionally the created ContextBinding also serves as a BindingContext for other bindings, just like a Context added with setBindingContext would do.

    Not confusing at all, right ;)?

    Reading the code for ManagedObject might help you to understand the internals better. (bindObject = bindElement)

    0 讨论(0)
提交回复
热议问题