1

I have a problem with a getBinding using UI5. I can bind a List to a JSON Model like so.

var sServiceUrl = "http://localhost:56154/api/store";
var myModel = new sap.ui.model.json.JSONModel();
myModel.loadData(sServiceUrl);
oView.setModel(myModel);

Alternatively, I can specify a 'name' for the model by changing the last line as follows:

oView.setModel(myModel, "foo");

Both work fine! I reference them (in my XML views) as below (items attribute refers).

Without a named reference to the mode:

<List items="{/}">

With a named reference to the mode:

<List items="{foo>/}">

Problem Statement

This command fails when I attempt to retrieve the binding context (in the case of the named model. the exact issue is getBindingContext() is undefined).

var sPath = oEvent.getParameter("listItem").getBindingContext();

Can anyone help me understand what to do - I presume the '>' in may cause the problem but given naming a model is standard/good practice. I am not sure why this should cause the function to fail.

Boghyon Hoffmann
  • 17,103
  • 12
  • 72
  • 170
Bernard
  • 1,208
  • 8
  • 15
  • Does this answer your question? [getBindingContext() returns undefined](https://stackoverflow.com/questions/36913868/getbindingcontext-returns-undefined) – Boghyon Hoffmann Jul 17 '21 at 13:16

1 Answers1

3

You have to pass the model name to the method:

oEvent.getParameter("listItem").getBindingContext("foo")
matbtt
  • 4,230
  • 19
  • 26