以编程方式更改值时,Dojo Slider onChange事件触发

时间:2015-01-08 13:27:22

标签: dojo slideshow

我有多个互连的Dojo Horizo​​ntalSlider。在滑块的onChange事件中,更新其他滑块的值。以编程方式更改值会触发相应滑块的onChange事件,该事件将再次触发其自身的onChange事件并覆盖这些值。

我确实需要设置intermediateChanges = true,这使得priorityChange标志在这种情况下无用。此外,我尝试设置一个变量,检查一个滑块是否有效,但由于时间问题,这也不起作用。

带有两个滑块的简化示例:

var sliding = false;

var slider1 = new HorizontalSlider({
                value: 70,
                minimum: 0,
                maximum: 100,
                discreteValues: 101,
                intermediateChanges: true,
                onChange: function() {
                    if (sliding == false) {
                        sliding = true;
                        new_value = [...]
                        slider2.set("value", new_value, false);
                    };
                    sliding = false;
                }
            }, "slider1");

var slider2 = new HorizontalSlider({
                value: 30,
                minimum: 0,
                maximum: 100,
                discreteValues: 101,
                intermediateChanges: true,
                onChange: function() {
                    if (sliding == false) {
                        sliding = true;
                        new_value = [...]
                        slider1.set("value", new_value, false);
                    };
                    sliding = false;
                }
            }, "slider2");

slider1.startup();
slider2.startup();

我也找到了这个例子,它似乎解决了Dojo Select的同样问题:Dojo Select onChange event firing when changing value programatically

如何以编程方式更改其值时阻止触发滑块的onChange事件?

谢谢!

1 个答案:

答案 0 :(得分:0)

也许有点难看,但你可以这样做:

var sliding = false;

var slider1 = new HorizontalSlider({
                value: 70,
                minimum: 0,
                maximum: 100,
                discreteValues: 101,
                intermediateChanges: true,
                onChange: function() {
                    if (sliding == false) {
                        sliding = true;
                        new_value = [...]
                        slider2.set("intermediateChanges", false);
                        slider2.set("value", new_value, false);
                        slider2.set("intermediateChanges", true);
                    };
                    sliding = false;
                }
            }, "slider1");

var slider2 = new HorizontalSlider({
                value: 30,
                minimum: 0,
                maximum: 100,
                discreteValues: 101,
                intermediateChanges: true,
                onChange: function() {
                    if (sliding == false) {
                        sliding = true;
                        new_value = [...]
                        slider1.set("intermediateChanges", false);
                        slider1.set("value", new_value, false);
                        slider1.set("intermediateChanges", true);
                    };
                    sliding = false;
                }
            }, "slider2");

slider1.startup();
slider2.startup();