gpt4 book ai didi

reactjs - React Component 将 Proxy 对象而不是 Event 对象传递给处理函数

转载 作者:行者123 更新时间:2023-12-03 13:38:25 25 4
gpt4 key购买 nike

我准备了以下React组件(React版本1.5.2):

var QuickSearch = React.createClass({

searchHandler: function(){
this.props.parent.props.dataSource.search = this.refs.SearchInput.value;
this.props.parent.props.dataSource.setPage(1);
this.props.parent.getData();
},

refreshHandler: function(){
this.props.parent.props.dataSource.search = this.refs.SearchInput.value;
this.props.parent.getData();
},

myEventHandler: function(evt){
console.log(evt);
if(evt.keyCode === 13) {
evt.stopPropagation();
this.searchHandler();
}
},


render: function(){

/* Translation function from table model */
_ = this.props.parent.props.table_model.gettrans;

return(
<div className="reactable-quicksearch-wrapper">
<input ref="SearchInput" type="text" onKeyPress={this.myEventHandler} placeholder={_('Search phrase...')} />
<button ref="SearchButton" type="button" onClick={this.searchHandler}>{_('Search')}</button>
<button ref="RefreshButton" type="button" onClick={this.refreshHandler}>{_('Refresh')}</button>
</div>
);
}

});

myEventHandler 函数作为“evt”传递包含“目标”(基本上是输入)和处理程序的代理对象:

Proxy { <target>: Object, <handler>: Object }

我不知道为什么,但它的行为似乎像“提交”(??)无论如何,从我读到的 react 应该传递标准事件对象,但它没有。

什么会导致这种行为?

最佳答案

这是预期的行为。 React 不使用 native 事件来解决浏览器不一致问题,而是使用 SyntheticEvent s。不过有些东西看起来很奇怪。 IIRC 类名是 SyntheticEvent,而不是 Proxy。

关于reactjs - React Component 将 Proxy 对象而不是 Event 对象传递给处理函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41481252/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com