Reactjs 使用React Native搜索栏

Reactjs 使用React Native搜索栏,reactjs,meteor,react-native,react-native-flatlist,Reactjs,Meteor,React Native,React Native Flatlist,我试图从react native searchbar添加一个搜索栏来过滤列表,如下所示,但它抛出了一个错误: 副手没有定义 我不知道从这里该怎么办,对不起,在RN很新!数据来自流星应用程序 class Flat_List extends Component{ constructor(props){ super(props); this._handleResults = this._handleResults.bind(this); this.state = { da

我试图从
react native searchbar
添加一个搜索栏来过滤列表,如下所示,但它抛出了一个错误:

副手没有定义

我不知道从这里该怎么办,对不起,在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);
类平面列表扩展组件{
建造师(道具){
超级(道具);
this.\u handleResults=this.\u handleResults.bind(this);
this.state={dataSource:{reports}};
}
_HandlerResults(结果){
this.setState({dataSource:this.props.represents(results)})
}
render(){
const{depress}=this.props;//列表在这里
返回(
this.searchBar=ref}
数据={depents}
handleResults={this.\u handleResults.bind(this)}
显示加载
allDataOnEmptySearch
隐藏
自动更正={false}
/>
项目.\u id}
renderItem={({item})=>(
)} />
);
}
导出默认createContainer(参数=>{
Meteor.订阅(“代理”);
return{deposts:Meteor.collection('deposts').find()};
},平面图);

您的州声明无效。在构造函数()中添加/编辑这些行:

仅在
此之前添加此行。状态

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

或者你可以直接把它放到->
this.state{dataSource:props.depress}

你能把代码发布到
平面列表的父级
/它的调用站点吗?很可能您没有准确地传递
props
,因为它们没有定义,但是如果我们可以看到父组件,那么调试就更容易了。实际上,这是父组件,数据来自导出默认的createContainer(params=>{Meteor.subscribe('subscribe');return{subscribes:Meteor.collection('subscribes')。find(),};},平面列表);好的,首先要确保调用
render
this.props.depents
已到达。如果不是,则不会对其进行定义。这是你的第一步。您可以使用三元运算符
this.props.repres添加数据到达的检查?this.props.repres:[“数据未到达”]
-如果数据未到达,则在调用
渲染时将未定义它。代码还有一些其他问题,但是从这里开始!好的,我试试看。我是否应该将表达式放在render()之后,就像这样。props.reports?this.props.deposes:[“数据未到达”]?是的,将其作为
render
console.log中的第一行放入。然后将其记录下来。或者您可以直接将其置于->this.state{dataSource:props.deposes}中。您确定要将此道具传递给此组件吗?它说“代理未定义”你能告诉我们你是如何将代理传递到你的组件中的吗?我将RN从这个组件连接到Meteor应用程序,如下所示:导出默认的createContainer(参数=>{Meteor.subscribe('subscribe');返回{subscribes:Meteor.collection('subscribes')。find()};},平面列表);
constructor(props){

   super(props);
   this._handleResults = this._handleResults.bind(this);
   this.state={
      dataSource : {deputies} // Here -> You doesn't define deputies
   }
} 
const { deputies } = props // You don't need 'this' because 'props' is already in the constructor params.