I am trying to pass element ID as one of the function's parameters:
sap.ui.getCore().byId("idView1").getController().addField("selectedFieldsContainer", oItem);
The definition of the addField
function is as follows:
addField: function(sId, oItem){
var oSelectedFieldsContainer = sap.ui.getCore().byId(sId);
oSelectedFieldsContainer.addItem(oItem);
}
When I run the code, I get error:
Uncaught TypeError: Cannot read property 'addItem' of undefined
But if I try to explicitly define the id:
sap.ui.getCore().byId("idView1").getController().addField(oItem);
while the function's definition is:
addField: function(oItem){
var oSelectedFieldsContainer = sap.ui.getCore().byId("selectedFieldsContainer");
oSelectedFieldsContainer.addItem(oItem);
}
the code works.
I don't understand why the first example doesn't work.
What am I missing?
Thank you.
UPDATE
HERE is JSBIN. I want to update control's type. I try to pass this control's id as a parameter, but sap.ui.getCore().byId()
can't find it (see console message).