Firebase 为什么react本机映射功能不能正常工作?
我正在尝试从firebase firestore检索数据。firestore中的数据记录在控制台上,但在我使用组件时不显示Firebase 为什么react本机映射功能不能正常工作?,firebase,react-native,redux-firestore,Firebase,React Native,Redux Firestore,我正在尝试从firebase firestore检索数据。firestore中的数据记录在控制台上,但在我使用组件时不显示 renderList = () => { const { accounts } = this.props accounts && accounts.map((account) => { return ( <View>
renderList = () => {
const { accounts } = this.props
accounts && accounts.map((account) => {
return (
<View>
<Text>{account.accountName}</Text>
{console.log(account.accountName)}
</View>
)
})
}
render() {
return (
<>
{this.renderList()}
</>
)
}
renderList=()=>{
const{accounts}=this.props
accounts&&accounts.map((account)=>{
返回(
{account.accountName}
{console.log(account.accountName)}
)
})
}
render(){
返回(
{this.renderList()}
)
}
在上面的编码控制台中,log(account.accountName)正在工作,但未在呈现方法中打印。我需要用这些数据创建一个列表。请尝试以下操作:
renderList = () => {
const { accounts } = this.props;
if(accounts){
return accounts.map((account) => {
return (
<View>
<Text>{account.accountName}</Text>
{console.log(account.accountName)}
</View>
)
})
}
}
render() {
return (
<>
{this.renderList()}
</>
)
}
renderList=()=>{
const{accounts}=this.props;
如果(账户){
返回帐户。映射((帐户)=>{
返回(
{account.accountName}
{console.log(account.accountName)}
)
})
}
}
render(){
返回(
{this.renderList()}
)
}
希望有帮助请尝试以下内容:
renderList = () => {
const { accounts } = this.props;
if(accounts){
return accounts.map((account) => {
return (
<View>
<Text>{account.accountName}</Text>
{console.log(account.accountName)}
</View>
)
})
}
}
render() {
return (
<>
{this.renderList()}
</>
)
}
renderList=()=>{
const{accounts}=this.props;
如果(账户){
返回帐户。映射((帐户)=>{
返回(
{account.accountName}
{console.log(account.accountName)}
)
})
}
}
render(){
返回(
{this.renderList()}
)
}
希望有帮助您是否尝试过在视图中使用渲染列表?尝试过,不起作用抱歉,您没有在渲染列表中返回任何内容。您创建了一个JSX from map函数,但还必须返回它。只要把return关键字放在帐户后面&&…是的,伙计。如果您想了解ES6语法和JS数组的功能,您的回答是正确的:您是否尝试在视图中使用renderList?尝试过,不起作用抱歉,您没有在SDE renderList中返回任何内容。您创建了一个JSX from map函数,但还必须返回它。只要把return关键字放在帐户后面&&…是的,伙计。如果您想了解ES6语法以及JS数组如何工作,那么您就错了:它正在工作。你是个天才。这两者之间的区别是什么?你看,你没有从renderListView返回任何东西,所以我只是添加了一个返回语句。很高兴这有帮助。如果你认为这是正确的答案,也要将其标记为已接受:)它起作用了。你是个天才。这两者之间的区别是什么?你看,你没有从renderListView返回任何东西,所以我只是添加了一个返回语句。很高兴这有帮助。如果你认为这是正确的答案,也要将其标记为已接受:)