Sometimes, it can be useful to hide a layer in your app. The better way to hide a layer in a layers tree is to add a "hidden form" to your layer in the Mapeditor. Add this option to your Form or create a new one with this option in it.
NOTE 1: You must activate grouping option ( "enable_grouping": true) in the web App JSON config.
NOTE 2: This form can be attached to a base layer.
context.datasources.display_in_layer_tree = false;
NOTE: Layer index starts from the top of layer tree at position 0.