2017-12-15 24 views
-1

반응 네이티브 검색 창에서 검색 창을 추가하여 목록을 필터링하려고합니다. 그러나 이렇게하면 오류가 발생하고 대리인은 정의되지 않습니다. 나는 여기서 뭘해야할지 모르겠다. 죄송합니다, RN에서 아주 새로운 것입니다! 데이터는 유성 앱에서 가져옵니다.검색 바 원제 네이티브를 사용하여

class Flat_List extends Component{ 

    constructor(props){ 
    super(props); 
    this._handleResults = this._handleResults.bind(this); 
    this.state = { dataSource : { deputies } }; 
    } 

    _handleResults(results){ 
    this.setState({dataSource: this.props.deputies(results)}) 
    } 

    render(){ 
    const {deputies}= this.props; // the list is here 

    return(
     <View> 

     <SearchBar 
      ref={(ref) => this.searchBar = ref} 
      data={deputies} 
      handleResults={this._handleResults.bind(this)} 
      showOnLoad 
      allDataOnEmptySearch 
      hideBack 
      autoCorrect= {false} 
     /> 

     <List> 
      <FlatList 
      data={this.props.deputies} 
      keyExtractor={(item)=> item._id} 
      renderItem={({item})=>(
      <DeputyDetail deputy={item.depute} navigation={this.props.navigation} />)} /> 
     </List> 

     </View> 
    ); 
    } 
export default createContainer(params => { 
    Meteor.subscribe('deputies'); 
    return { deputies: Meteor.collection('deputies').find() }; 
}, Flat_List); 
+0

당신이 게시 할 수 'Flat_List'/그것의 호출 사이트의 부모를위한 코드? 'props'는 정의되지 않았기 때문에 정확하게 전달하지 않을 것이지만, 부모 컴포넌트를 볼 수 있다면 디버그하는 것이 더 쉽습니다. –

+0

는 사실이 부모 인, 데이터는 수출 기본 createContainer에서 온다 (PARAMS => { Meteor.subscribe ('대리인'); 반환 { 대표 : Meteor.collection ('대리인') (찾기), . }; }, Flat_List); – Sonia

+0

좋습니다,'this.props.deputies'가'render'가 호출 될 때까지 도착하는지 확인하여 시작하는 것이 좋습니다. 그렇지 않은 경우 정의되지 않습니다. 그것은 당신의 첫 번째 단계입니다. 삼항 연산자'this.props.deputies? '를 사용하여 데이터가 도착했는지 체크를 할 수있다. this.props.deputies : [ "Data not arrived"]'- 도착하지 않으면'render is called '할 때 정의되지 않을 것입니다. 코드에는 몇 가지 다른 문제가 있지만 시작하십시오! –

답변

0

주의 신고가 잘못되었습니다. 추가/편집이 줄을() 생성자에 :

const { deputies } = this.props; 
this.state={ 
    dataSource: deputies 
} 
+0

이 시도했지만 성공하지 못했습니다 – Sonia

+0

"대리인이 정의되지 않았습니다"라고 말합니다 – Sonia

+0

'대리모'를 어떻게 ''구성 요소로 전달하는지 보여줄 수 있습니까? – jkhedani

0
constructor(props){ 

    super(props); 
    this._handleResults = this._handleResults.bind(this); 
    this.state={ 
     dataSource : {deputies} // Here -> You doesn't define deputies 
    } 
} 

this.state 전에이 줄을 추가 :

const { deputies } = props // You don't need 'this' because 'props' is already in the constructor params. 

또는 당신은 직접 넣을 수 있습니다 ->this.state{ dataSource: props.deputies }

+0

또는 직접 넣을 수 있습니다 -> this.state {dataSource : props.deputies} –

+0

"대리인이 정의되지 않았습니다"라는 오류가 발생합니다 – Sonia

+0

이 구성 요소에이 소품을 전달 하시겠습니까? –