2

I know that you can get a single Component with:

sap.ui.component("ComponentID");

But is there also a way to list all components that live in the current window context?

Thx Chris

cschuff
  • 5,502
  • 7
  • 36
  • 52

2 Answers2

1

sap.ui.component(string) delegates to sap.ui.getCore().getComponent(). With that you can query a specific component by id.

There at the sap.ui.core.Core is a registry of components. But its marked as private and even has a TODO to get rid of it. So i would advice to not access that directly.

schnoedel
  • 3,918
  • 1
  • 13
  • 17
  • 1
    Not only is it not recommendable to use this registry it is not accessible from sap.ui.getCore()... – cschuff May 17 '16 at 19:09
0

You can get the available components through Component.registry.

> sap.ui.core.Component.registry.all()
{component-name: fnClass}

// You can use Object.keys to get the names
> Object.keys(sap.ui.core.Component.registry.all())
['component-name']

And then you can use this name to fetch the actual component, either through Core.getComponent, Component.get or Componeny.registry.get (and i wouldn't even be surprised if where a dozen other options in the documentation).

> sap.ui.getCore().getComponent("component-name") // pre 1.95
> sap.ui.core.Component.get("component-name") // post 1.95
fnClass {_oMetadataProxy: UIComponentMetadata, _oManifest: constructor, _mManifestModels: {…}, _mServices: {…}, getMetadata: ƒ, …}
Joost
  • 3,169
  • 2
  • 22
  • 40