【发布时间】:2021-10-21 17:51:08
【问题描述】:
- 我建立了一个平面列表,其中客户名称只有名称。
- 现在我想单击这些名称以显示客户详细信息我在 Fire Store 中有详细信息 数据库。
- 只需要您的帮助来解决这个问题。
- 此屏幕中有姓名和电子邮件,数据库中有更多关于此详细信息的信息。比如联系电话、地区、时间和日期等。
import React, { useEffect, useState } from 'react';
import { FlatList, StyleSheet, Text, TouchableOpacity, View } from 'react-native';
import { db } from "../firebase";
function DetailsScreen() {
const [contacts, setContacts] = useState([]);
var today = new Date();
var dd = today.getDate();
var mm = today.getMonth() + 1;
var yyyy = today.getFullYear();
today = mm + '/' + dd + '/' + yyyy;
// 'createdDate', '>=', last7DayStart FOR LAST WEEK THIS LOGIC
// 'createdDate', '>=', lastMonthThisDay FOR LAST MONTH THIS LOGIC
// var last7DayStart = moment().startOf('day').subtract(1, 'week').format('M/DD/YYYY');
// var lastMonthThisDay = moment().startOf('day').subtract(1, 'month').format('M/DD/YYYY');
// var yesterdayEndOfRange = moment().endOf('day').subtract(1, 'day').format('D/MM/YYYY');
// console.log(last7DayStart);
useEffect(() => {
const fetchData = async () => {
const data = await db.collection("contacts").where('createdDate', '<', today).get();
setContacts(data.docs.map((doc) => ({ ...doc.data(), id: doc.id })));
};
fetchData();
}, []);
function handleUpdate() {
alert("updated")
};
function handleDelete() {
alert("Successfully Removed")
};
return (
<FlatList
style={styles.list}
data={contacts}
renderItem={({ item }) => <Text style={styles.text} numberOfLines={9}>
<Text style={styles.text1}> Student Details </Text>
{"\n"}
{"\n"}
Name: {item.name}
{"\n"}
Email: {item.email}
<TouchableOpacity
onPress={() => handleUpdate()} style={{ paddingTop: 10 }}>
<Text style={{ borderWidth: 0.80 }}> Update </Text>
</TouchableOpacity>
<TouchableOpacity
onPress={() => handleDelete()} style={{ paddingLeft: 20 }}>
<Text style={{ borderWidth: 0.75 }}> Delete </Text>
</TouchableOpacity>
</Text>}
/>
)
};
export default DetailsScreen;
const styles = StyleSheet.create({
container: {
flex: 1,
justifyContent: 'flex-start',
alignItems: 'flex-start',
paddingTop: 5,
},
text: {
fontSize: 15,
fontStyle: 'italic',
paddingLeft: 15,
marginHorizontal: 20,
borderBottomWidth: 1,
paddingBottom:10
},
list: {
flex: 1,
paddingTop: 10,
backgroundColor: '#fff'
},
text1: {
flex: 1,
fontSize: 18,
fontWeight: 'bold',
paddingTop:5
}
});
【问题讨论】:
-
请更新您的问题以包含Minimal, Complete, and Reproducible Code Example 来说明您已经完成的工作,并包含有关任何问题的明确详细信息。我们无法帮助修复我们看不到的代码。
-
@DrewReese 请看看我应该怎么做。如果我使用它,我是否必须使用 touchableOpacity,然后如何查看所有细节。道具或类似的东西。
-
我会将
renderItem逻辑抽象为一个具有切换状态的 React 组件,该状态有条件地呈现附加的详细信息值。 -
我不知道您在说什么,请您分享对我非常有益的代码。
标签: reactjs react-native react-native-android mobile-development