刷新dat.gui变量 [英] Refreshing dat.gui variable

查看:256
本文介绍了刷新dat.gui变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是dat.gui界面中的下拉列表。单击任何数字后,jumpSwitcher就是您选择的任何数字。我正在尝试根据用户为 Starsystem 选择的内容替换与他们的特定号码相关的每个列表。





所以 solPlanets = ['Ilos','Tuchanka','Illium',单击2时, Palaven] 出现在列表2中。默认情况下,solPlanets显示[[Mercury], Venus, Earth, Mars, Jupiter, 土星,天王星,海王星],因为默认值为jumpSwitcher = 1。



问题是,列表始终显示为 solPlanets = ['mercury','Venus','Earth','Mars,'Jupiter','Saturn','Uranus','Neptune'] ,无论jumpSwitcher是否为2。 p>

我通过在jumpSwitcher为2时放置一条警报消息来确认这一点,并且警报会弹出,但列表不会更改。
这很可能与dat.gui不会更新的类似问题有关。
我尝试过listen()方法,因为它是给出的主要答案,但它对我没有用。



我已经制作了小提琴



PS:我之前曾问过这个问题,但现在我意识到这很可能与dat.gui无关,它不刷新值而不是JavaScript。因此,我删除了这个问题,因为它可能会误导观众,并且我没有为此摆弄任何东西。

解决方案

您必须为行星列表重新创建扭曲器。



我修改了jsfiddle示例此处

 函数updatePlanets(id){
var controller = gui .__ controllers [2];
controller.remove();
gui.add(data,'Planets',planets [id])。onChange(doSomeStuff);

//返回0个元素
data.Planets = 0;
gui .__ controllers [2] .updateDisplay();
}

此外,当我更改DAT.GUI的版本时,它开始工作。到0.6.1


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.

解决方案

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

这篇关于刷新dat.gui变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆