2017-01-05 28 views
3

핸들러 함수에 이벤트 객체 대신 프록시 객체를 전달 반작용 (버전 1.5.2 반응) : "EVT"로가 구성 요소 내가 반응 다음과 같은 구성 요소를 준비했습니다

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

 
});

이 MyEventAPIHandler 기능을 프록시 "대상"을 포함하는 객체 (기본적으로 입력) 및 핸들러 전달합니다

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

내가 더 있는지를 생각하지 왜,하지만 "S처럼 행동하는 것 ubmit "(??) 어쨌든, 내가 읽은 반응에서 표준 이벤트 객체를 전달해야하지만 그렇지 않습니다.

어떤 종류의 문제가 발생할 수 있습니까?

답변

1

이것은 예상되는 동작입니다. React는 브라우저 불일치를 해결하기 위해 네이티브 이벤트를 사용하지 않으며 SyntheticEvent을 사용합니다. 뭔가 이상하게 보입니다. IIRC 클래스 이름은 Proxy가 아닌 SyntheticEvent입니다.

+0

(프록시 포함) : [SyntheticEvent <.apply/<.set () 기본적으로 입력 개체로 렌더링됩니다. – PiWo