【问题标题】:Using flex makes autocomplete list overlay on other element使用 flex 使自动完成列表覆盖在其他元素上
【发布时间】:2018-07-08 19:21:52
【问题描述】:

我正在使用 flatlist 制作自动完成文本框。 我想在我拥有的每个元素之上显示一个列表。 现在当自动完成显示。它将另一个文本框推开。

2 个自动完成文本框:

当文本框显示一个列表并且他们将另一个文本框推开时:

【问题讨论】:

    标签: css react-native autocomplete flexbox


    【解决方案1】:

    应该这样做:

        <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',
      }
    });
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2017-07-17
      • 2013-03-03
      • 2013-11-26
      • 2020-09-27
      • 2013-10-19
      • 2019-04-29
      • 1970-01-01
      相关资源
      最近更新 更多