I am trying to figure out if it's possible to update just the dropdown list values for a dat.gui controller.
var gui = new dat.GUI();
gui.add(this, 'toggle').onChange( updateToggle );
gui.add(item, 'template', [ 'A', 'B', 'C', 'D' ]).onChange( updateTemplate );
When the toggle is changed, i want to modify the template options:
if (startRibbon) {
gui.__controllers[1].options(['A', 'B']);
} else {
gui.__controllers[1].options(['A', 'B', 'C', 'D']);
};
This does change the values, but it creates a new template controller with a new index (deleting the previous one) and making it not work the next time. It also pushes the new one to the bottom of the controller list.
Before I add more code to try and chase after the new modified/new controller, I figured I should see if anybody has a better way.
You can use the function
options
. I code this for example purposes. I hope you can adapt it.Here you can find the live code.