admin管理员组文章数量:1291250
When generating a dat.GUI dropdown menu, I give an array of strings that will be the dropdown menu entries. Upon a user selection, the corresponding data property is updated to be the selected menu string.
Is there a way to separate the strings in the menu from the corresponding values (which could be of any type)?
For example, say my menu is ['King', 'Queen', 'Rook']
, I'd like my property to get the values resp. ['A','B','C']
or [-1, 9, 5]
.
When generating a dat.GUI dropdown menu, I give an array of strings that will be the dropdown menu entries. Upon a user selection, the corresponding data property is updated to be the selected menu string.
Is there a way to separate the strings in the menu from the corresponding values (which could be of any type)?
For example, say my menu is ['King', 'Queen', 'Rook']
, I'd like my property to get the values resp. ['A','B','C']
or [-1, 9, 5]
.
1 Answer
Reset to default 9Yes.
Imagine the example below,
gui = new dat.GUI();
var text =
{
speed: 'someName'
}
gui.add(text, 'speed', { King: 'A', Queen: 'B', Rook: 'C' } );
The first thing to do is to determine if it is a controller (above) or a folder. If it's the former, then the location of the dropdown menu can be found in the gui.__controllers
(otherwise, if it is the latter, then the location can be found in the gui.__folders
. If you have multiple controllers you will have to determine the appropriate controller for the dropdown menu - it will be along the lines of dat.controllers.OptionController.e
.
Assuming it's your only controller, then you can access it by, gui.__controllers[0]
.
The next step is to figure out what the user has selected. Each controller with a dropdown menu will have a __select
option. Inside each __select
option, there is a selectedOptions
, which details what the user has chosen.
This will be in the form of, gui.__controllers[0].__select.selectedOptions[0].value
.
If King is selected the value that is returned is A.
本文标签: javascriptMap datGUI Dropdown Menu Strings to ValuesStack Overflow
版权声明:本文标题:javascript - Map dat.GUI Dropdown Menu Strings to Values - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741509826a2382542.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论