7

I'm using dat.GUI and want to replace a folder with new content.

var gui = new dat.GUI();
var folder = gui.addFolder('someString');

// sometime later ...
var newFolder = gui.addFolder('someString'); // causes an error

So I need a way to remove the previous folder or replace its content.

Any ideas?

Stefan Ramson
  • 531
  • 1
  • 6
  • 18

1 Answers1

13

This solution worked for me. You need to add this function to the dat.GUI file or manually add it in your code:

dat.GUI.prototype.removeFolder = function(name) {
  var folder = this.__folders[name];
  if (!folder) {
    return;
  }
  folder.close();
  this.__ul.removeChild(folder.domElement.parentNode);
  delete this.__folders[name];
  this.onResize();
}

Check it out here: dat.gui how to hide menu with code

Community
  • 1
  • 1
André Lago
  • 146
  • 3
  • 3
  • The only problem with this solution is that when we destroy dat.gui using dat.gui.destory() this will not remove all the registered events which could be a bummer for performance. – Samiullah Khan Jan 20 '20 at 11:51