searchBar的React-Native NativeBase onChangeText事件

时间:2018-03-07 15:45:47

标签: react-native native-base

我正在尝试在搜索栏的NativeBase上触发事件onChangeText,但我无法弄清楚如何做到这一点。这是我到目前为止所拥有的

如果onChangeText在这里工作,警报根本没有显示?

_onChangeSearchText(text) {

    //do something

}


render() {
    return (
      <Container>
          <Header searchBar rounded
          onChangeText={this._onChangeSearchText.bind(this)}
          autoCorrect={false}>
            <Item>
              <Icon name="ios-search" />
              <Input placeholder="Search" />
              <Icon name="ios-people" />
            </Item>
            <Button transparent>
              <Text>Search</Text>
            </Button>
          </Header>
        </Container>
    );
}

1 个答案:

答案 0 :(得分:3)

Header没有onChangeText道具。您必须将onChangeText传递给Input

render() {
    return (
      <Container>
          <Header searchBar rounded autoCorrect={false}>
            <Item>
              <Icon name="ios-search" />
              <Input
                onChangeText={this._onChangeSearchText.bind(this)} // <-- Here
                placeholder="Search"
              />
              <Icon name="ios-people" />
            </Item>
            <Button transparent>
              <Text>Search</Text>
            </Button>
          </Header>
        </Container>
    );
}