我正在尝试对我已设法做到的操作使用去抖,但是我想将 e 作为参数传递,但它不起作用。我有什么办法可以做到这一点吗?
constructor(props, context) {
super(props, context);
this.testing = _.debounce(this.testing.bind(this), 2000);
}
@action testing(e) {
alert("debounced!!");
//use e.target ...
}
如果我拿走 e 它将进入该函数,否则不会。我应该怎么做才能解决这个问题?
您可以利用事件.persist() https://facebook.github.io/react/docs/events.html#event-pooling将事件传递给 debounce 方法。
根据文件:
如果您想访问事件属性asynchronous
方式,你
应该打电话event.persist()
在该事件上,这将删除
从池中合成事件并允许对事件的引用
由用户代码保留。
所以你可以将该事件用作
constructor(props, context) {
super(props, context);
this.testing = _.debounce(this.testing.bind(this), 2000);
}
@action testing(e) {
alert("debounced!!");
//use e.target ...
}
onChange = (e) => {
e.persist();
this.testing(e);
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)