2017-12-15 22 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

さて、 'render.do'が呼ばれるまでに' this.props.deputies'が到着していることを確認することから始めたいと思います。そうでない場合は、定義されません。それがあなたの最初の一歩です。データが到着したというチェックを、3項演算子 '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

このコンポーネントにこの小道具を渡してもよろしいですか? –

関連する問題