消息关闭
    暂无新消息!

class 父组件 extends Component {
constructor(props) {

super(props);console.log('module');
this.state= {text: '',customers : []};
this.searchCustomer = this.searchCustomer.bind(this);

}

searchCustomer(text){console.log(text);

this.state.text = text.text;
let t = text.text;
const bagArray = this.props.data;
const resultArray = [];
if(t.length > 0 && bagArray){
  for(let i=0;i<bagArray.length;i++) {
    if(bagArray[i].name.indexOf(t) >= 0 || bagArray[i].iphone.indexOf(t)>=0 || bagArray[i].wxNumber.indexOf(t)>=0){
      resultArray.push(bagArray[i]);
    }
  }
}
this.state.customers = resultArray;console.log('state');console.log(this.state);

}

render() {

return (
  <View style={styles.container}>
    <SearchInput callback={this.searchCustomer}/>
    <CustomerList dataSource={this.state.customers}/>//这是子组件
  </View>
);

}
}

这段就是父组件的代码,第一次渲染是空的Array,等输入搜索词之后通过searchCustomer方法的回调,给父组件的 state.customer赋值,子组件customerList 是一个 ListView ,父组件的state 的改变后 怎么能做到子组件customerlist 重新刷新


1个回答