在onDragStop事件中获取材料ui滑块值(反应) [英] Get material ui slider value in onDragStop event (react)

查看:50
本文介绍了在onDragStop事件中获取材料ui滑块值(反应)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在React应用中使用材质ui Slider 触发事件 onDragStop 而不是 onChange 次).但是,文档表示 onDragStop 函数签名仅具有mouseevent: function(event:object)=>无效.因此,以下代码可用于 onChange :

I want to fire an event onDragStop rather than onChange using a material ui Slider in my React app (so that the event fires fewer times). However, the documentation indicates that the onDragStop function signature only has the mouseevent: function(event: object) => void. So, the following works with onChange:

<Slider onChange={ (e, val) => this.props.update(e, control.id, val) }  />

但是,此事件没有第二个参数 val :

However, this event doesn't have a second parameter val:

<Slider onDragStop={ (e, val) => this.props.update(e, control.id, val) }  />

如何在 onDragStop 函数中获取Slider的当前值?请注意,我无法使用 this ,因为它是指父组件.

How can I get the current value of the Slider in the onDragStop function? Note, I'm unable to use this, as it refers to the parent component.

推荐答案

也遇到了这个问题!如果您在类中使用组件,请同时使用两个回调:

Also ran into this problem! If you use a component inside a class, use both callbacks:

<Slider onChange={ (e, val) => this.val = val }  
        onDragStop={ (e) => this.props.update(e, control.id, this.val)
/>

这篇关于在onDragStop事件中获取材料ui滑块值(反应)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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