Pra*_*jna 7 autocomplete npm react-native
我想要一个文本输入框,它应该在键入时显示建议,如果没有建议,它应该采用键入的输入,否则它应该从建议数组中获取输入。我怎样才能实现这个目标?我浏览了一些文档和模块react-native-autocomplete-input,但无法理解代码。谁能帮我吗。
小智 0
<Autocomplete
autoCapitalize="none"
autoCorrect={false}
containerStyle={styles.autocompleteContainer}
//data to show in suggestion
data={films.length === 1 && comp(query, films[0].title) ? [] : films}
//default value if you want to set something in input
defaultValue={query}
/*onchange of the text changing the state of the query which will trigger
the findFilm method to show the suggestions*/
onChangeText={text => this.setState({ query: text })}
placeholder="Enter the film title"
renderItem={({ item }) => (
//you can change the view you want to show in suggestion from here
<TouchableOpacity onPress={() => this.setState({ query: item.title })}>
<Text style={styles.itemText}>
{item.title} ({item.release_date})
</Text>
</TouchableOpacity>
)}
/>
Run Code Online (Sandbox Code Playgroud)
从aboutreact.com得到这个,这里的评论解释了你想要传递到特定区域的内容。我建议尝试为 data 属性传递一个数组。
| 归档时间: |
|
| 查看次数: |
16857 次 |
| 最近记录: |