答案 0 :(得分:0)
这应该做到:
<TextInput placeholder="search" onChangeText={(text) => this.populateList(text)} />
<View>
<FlatList
style={{ position: 'absolute' }}
data={this.state.data}
renderItem={({ item }) => <Text>{item.key}</Text>}
/>
</View>
<TextInput placeholder="search" />
这是我用来测试的组件:
import React, { Component } from 'react';
import {
StyleSheet,
Text,
View,
FlatList,
TextInput
} from 'react-native';
export default class App extends Component {
constructor(props) {
super(props);
this.state = {
data: []
};
}
populateList = (text) => {
var characters = text.split("");
var data = [];
characters.forEach(element => {
data.push({ key: element });
});
console.log(data);
this.setState({ data });
}
render() {
return (
<View style={styles.container}>
<TextInput placeholder="search" onChangeText={(text) => this.populateList(text)} />
<View>
<FlatList
style={{ position: 'absolute' }}
data={this.state.data}
renderItem={({ item }) => <Text>{item.key}</Text>}
/>
</View>
<TextInput placeholder="search" />
</View>
);
}
}
const styles = StyleSheet.create({
container: {
flex: 1,
justifyContent: 'center',
alignItems: 'center',
backgroundColor: '#F5FCFF',
}
});