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

Dojo Slider onChange event firing when changing value programmatically

我有多个互连的 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 事件?

谢谢!

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

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();