Refreshing dat.gui variable

怎甘沉沦 提交于 2019-12-24 01:10:48

问题


This is a dropdown list within a dat.gui interface. Once you click any number, the jumpSwitcher will be whatever number you chose. I’m trying to replace each list that pertains to their specific number based on that what the user chose for Starsystem.

So solPlanets= ['Ilos', 'Tuchanka', 'Illium', 'Palaven'] is what shows in list 2 when you click on 2. On default, solPlanets shows ['Mercury', 'Venus', 'Earth', 'Mars', 'Jupiter', 'Saturn', 'Uranus', 'Neptune'] because default is jumpSwitcher = 1.

Problem is, the list will always show as solPlanets= ['Mercury', 'Venus', 'Earth', 'Mars', 'Jupiter', 'Saturn', 'Uranus', 'Neptune'], no matter if jumpSwitcher is 2.

I confirmed this by placing an alert message if jumpSwitcher is 2, and the alert pops up, but the list won’t change. This is likely to do with similiar issues where dat.gui doesn't update. I've tried listen() method as it was the main given answer, but it hasn't worked for me.

I've made a fiddle of it.

PS: I've asked this question before but now I realise it's likely to do with dat.gui not refreshing values and not javascript. So I deleted that question because it was kind of reaching a wrong audience, and I didn't make a fiddle for it.


回答1:


You have to re-create the contorller for the list of planets.

I modified your jsfiddle example here. The main stuff in

function updatePlanets(id) {
    var controller = gui.__controllers[2];
    controller.remove();
    gui.add(data, 'Planets', planets[id]).onChange(doSomeStuff);

    //back to 0 element
    data.Planets = 0;
    gui.__controllers[2].updateDisplay();
}

Also, it started to work, when I changed the version of DAT.GUI to 0.6.1



来源:https://stackoverflow.com/questions/40341872/refreshing-dat-gui-variable

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!