我如何将Firebase输出更改为具有本机反应的文本

时间:2019-10-22 15:28:58

标签: firebase react-native expo

我想让输出在任何输出(更新,删除,创建)上说一个“ hi”而不是-LrM8rlKq1-dSW6XRt0 _({“ color:'blue”}),以及如何隐藏seletedid(-LrM8rlKq1-dSW6XRt0_)不在显示器上显示

///////////////////////////////////////////////// ///////////////////////////////////////////////////// ////////

enter image description here

 import React, { Component } from 'react';
    import { View, Text, StyleSheet, Button, TextInput, TouchableOpacity } from 'react-native';
    import firebase from './firebase';
    export default class App extends Component {
    carDatabase = firebase.database().ref('car');
     state = { cars: {}, selectedId: '' }
     // Read
     componentDidMount() {
       this.carDatabase.on('value', cars => {
         const carsJSON = cars.val();
         this.setState({ cars: carsJSON === null ? {} : carsJSON });
       })
       // this.carDatabase.push({color: 'yellow'})
     }
     // Create
     create() {
       this.carDatabase.push({color: 'yellow'})  
       this.setState({selectedId: ''})
     }
     // Update
     update() {
      this.carDatabase.child(this.state.selectedId).set({color: 'blue'}) 
      this.setState({selectedId: ''})
    }
     // Delete
     deleteCar() {
        if(this.state.selectedId === '') {
          return;

        }

       this.carDatabase.child(this.state.selectedId).set(null)
      this.setState({selectedId: ''})
    }
        render() {
            return (
                <View style={styles.container}>
                 <TextInput value={this.state.selectedId} style={styles.textInput}></TextInput>
                   <Button title="create" onPress={() => this.create()}></Button> 
                   <Button title="update" onPress={() => this.update()}></Button> 
                   <Button title="delete" onPress={() => this.deleteCar()}></Button> 
           {
             Object.keys(this.state.cars).map( (carId, index) =>
               <TouchableOpacity key={index} onPress={() => this.setState({ selectedId: carId})}>
                 <Text>{`${carId}: ${JSON.stringify(this.state.cars[carId])}`}</Text>
               </TouchableOpacity>
             )
           }

           {/* <Text>{JSON.stringify(this.state.cars, null, 2)}</Text> */}
         </View>
            );
        }
    }
    const styles = StyleSheet.create({
     textInput: {
       backgroundColor: 'green',
       height: 30,
       width: '100%'
     },
        container: {
            flex: 1,
            backgroundColor: '#fff',
            alignItems: 'center',
            justifyContent: 'center'
     }
    });


  [1]: https://i.stack.imgur.com/tQHSK.jpg

1 个答案:

答案 0 :(得分:0)

我在这里不太了解您的问题:只需删除代码的这一部分

$time_snamp = date('Ymdhisu');

$filename = $_FILES["file"]['name'];
$filename = $time_snamp . '_' . $filename;
$file = $_FILES["file"]['name'];

$targetPath = 'uploads/Targets/' . $filename;
move_uploaded_file($_FILES['file']['tmp_name'], $targetPath);

并替换为:

{
   Object.keys(this.state.cars).map( (carId, index) => (
      <TouchableOpacity key={index} onPress={() => this.setState({ selectedId: carId})}>
         <Text>{`${carId}: ${JSON.stringify(this.state.cars[carId])}`}</Text>
      </TouchableOpacity>
   )
}