通过if else语句显示特定的输出
Show specific output through if else statement
我正在研究如何在数据中显示下拉列表中的条目。基于用户输入的gui界面,但我遇到的问题与数据无关。GUI编程,而不是我缺乏javascript技能。
我有两个列表,一个显示Starsystem
和0
和1
作为名称。另一个是Planets
,显示了Starsystem
内部的特定行星。我如何编写这条语句,使这两个数组只在选择0或1时显示?
var jumpSwitcher = 0;
this.Starsystems = 'dat.gui';
//Starsystem list
gui.add(this, 'Starsystems', ['0', '1']).onChange(function(value) {
if (value === '1') {
jumpSwitcher = 1;
}
});
this.Planets = 'dat.gui';
//if the var jumpSwitcher is 0, display these variables in the Planets array.
if (jumpSwitcher === 0) {
Planets = ['Mercury', 'Venus', 'Earth', 'Mars', 'Jupiter', 'Saturn', 'Uranus', 'Neptune'];
}
//if the jumpSwitcher is 1, meaning if the user has clicked on "1" under the Starsystem, show these planets.
else if (jumpSwitcher === 1) {
Planets = ['Ilos', 'Tuchanka', 'Palaven', 'Illium'];
}
gui.add(this, 'Planets', Planets).name("Planets in this system").onChange(function(value) {
});
我想说,这应该工作,但不知何故它没有。当我简单地在语句中设置条件,如if (1>0) {show 1} else {show 2}时,它就会这样做。
PS:var jumpSwitcher = 1;
this.Starsystems = 'dat.gui';
gui.add(this, 'Starsystems', ['1', '2', '3', '4', '5', '6', '7', '8', '9', '10']).onChange(function(value) {
jumpSwitcher = +value;
});
this.Planets = 'dat.gui';
switch (jumpSwitcher) {
case 1:
gui.add(this, 'Planets', ['Mercury', 'Venus', 'Earth', 'Mars', 'Jupiter', 'Saturn', 'Uranus', 'Neptune']).name("Planets in this system").onChange(function(value) {
});
break;
case 2:
gui.add(this, 'Planets', ['Ilos', 'Tuchanka', 'Illium', 'Palaven']).name("Planets in this system").onChange(function(value) {
});
break;
}
需要重置jumpSwitcher
if (value === '1') {
jumpSwitcher = 1;
}
jumpSwitcher = +value;
设置jumpSwitcher
为一个数值。
另一种解决方案是,如果数组内的值连接在一起,则将数组内的值更改为数字值而不是字符串。
gui.add(this, 'Starsystems', [0, 1]).onChange(function(value) {
// ^^^^^^
jumpSwitcher = value;
});
相关文章:
- 如何在页面一侧的浮动框中显示用户脚本的输出
- 输出文本不't以正确格式显示
- 为什么我的Alexa技能测试显示正确的lambda输出,但在开发人员控制台中测试时却给出错误消息
- 如何在文本框中显示内部 HTML 输出
- 从一个文本框执行代码,并在另一个文本框中以 HTML 显示输出
- 将咖啡转换为javascript,并将结果显示在Emacs中的标准输出中
- 如何使用innerHTML显示多个输出
- 在命令运行时以Grunt显示输出
- TypeAhead.js没有显示任何输出Rails
- 让我的javascript输出显示在HTML中
- Javascript/JSON输出不;t显示
- 读取本地文件并将请求的输出显示到 html 文件
- 如何将执行输出显示到文本区域中
- 如何使多个JavaScript函数的输出显示在HTML中
- JS测试输出显示在控制台中,而它应该'不要使用Chrome和IE
- Json输出显示打印漂亮
- PHP图像标题输出显示
- 如何用JS输出显示在外部网页上的值
- 我的输出显示“;[对象HTMLInputElement]”;而不是我输入的总和
- AJAX PHP输出显示不正确