Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to find the Object type of a SAPUI5 element at runtime

Tags:

sapui5

I am wondering how to get the object type of a SAPUI5 Javascript object at runtime. I can check if the object is of a particular type like so:

myObj instanceof sap.m.List

I'm looking for the equivalent of .getClass() in the Java world. I've tried a few approaches described on various other SO threads such as How do I get the name of an objects type in Javascript

There doesn't seem to be a standard approach, and none I've tried seem to work for UI5. This isn't causing me a problem but debugging in dev tools with my Java head on it would be nice to get the object type and therefore know what methods I can call.

Cheers, Gregor

like image 533
gregor Avatar asked Feb 05 '14 16:02

gregor


1 Answers

There's a metadata mechanism:

oControl = sap.ui.getCore().byId('<your control id>');
sType = oControl.getMetadata().getName();

In fact the object returned from sap.ui.core.Element#getMetadata contains a whole heap of introspection goodness.

like image 151
qmacro Avatar answered Nov 06 '22 01:11

qmacro