复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53import Autocomplete from 'react-native-autocomplete-input' const API = 'https://swapi.co/api'; componentDidMount() { InteractionManager.runAfterInteractions(() => { fetch(`${API}/films/`).then(res => res.json()).then((json) => { console.log(json) const { results } = json; this.setState({ results: results }); }); }); } findFilm(query) { if (query === '') { return []; } const { results } = this.state; if (results) { return results.filter(film => film.title.toLowerCase().search(query) >= 0); } } render中: const { query } = this.state; const Last = this.findFilm(query); const comp = (a, b) => a.toLowerCase().trim() === b.toLowerCase().trim(); return( <View style={styles.container}> <Autocomplete autoCapitalize="none" autoCorrect={false} containerStyle={styles.autocompleteContainer} data={Last.length === 1 && comp(query, Last[0].title) ? [] : Last} defaultValue={query} onChangeText={text => this.setState({ query: text })} placeholder="请输入" renderItem={(title) => ( <TouchableOpacity onPress={() => this.setState({ query: title.item.title })}> <Text style={styles.itemText}> {title.item.title} </Text> </TouchableOpacity> )} /> <View style={styles.descriptionContainer}> {films.length > 0 ? this.renderFilm(films[0]) : <Text style={styles.infoText}> Enter Title of a Star Wars movie </Text> } </View> </View> )
年前更一波吧!!! 后续更新更多RN实用插件
最后
以上就是纯情跳跳糖最近收集整理的关于react-native-autocomplete-input 自动完成的全部内容,更多相关react-native-autocomplete-input内容请搜索靠谱客的其他文章。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复