Javascript 反应数组中的本机map()和JSX元素
尝试使用map()在React Native中呈现JSX元素数组(此.state中的tableData),但我在控制台上得到了一个包含未定义元素的数组 这是我的密码:Javascript 反应数组中的本机map()和JSX元素,javascript,arrays,react-native,jsx,Javascript,Arrays,React Native,Jsx,尝试使用map()在React Native中呈现JSX元素数组(此.state中的tableData),但我在控制台上得到了一个包含未定义元素的数组 这是我的密码: const TVSHOWIMAGETITLES = [ MoneyHeist, BreakingBad, MoneyHeist, BreakingBad, MoneyHeist, BreakingBad, MoneyHeist, BreakingBad, MoneyHeist]; clas
const TVSHOWIMAGETITLES = [
MoneyHeist, BreakingBad,
MoneyHeist, BreakingBad,
MoneyHeist, BreakingBad,
MoneyHeist, BreakingBad,
MoneyHeist];
class HashTablesScreenTwo extends React.Component {
constructor(props) {
super(props);
this.state = {
fiveShows: this.props.route.params.selectedShows,
tableHead: ['Week', 'TV Shows'],
tableWeeks: [1, 2, 3, 4, 5],
tableData: []
}
}
renderTableData(){
const jsxArray = this.state.tableWeeks.map((i)=>{this.renderTVShowImageTitle(i-1)})
console.log(jsxArray)
console.log(this.state.tableWeeks)
return{
tableData: jsxArray
}
}
renderTVShowImageTitle(i) {
let index = this.state.fiveShows[i];
return (
<TVShow
id={index}
imageSource={TVSHOWIMAGETITLES[index]}
onClick={() => 1}
/>
)
}
render() {
const state = this.state;
{ this.renderTableData() }
return (
<View>
<Text>
Because you're ambitious,
you have decided to binge watch the shows at a rate of one show per week.
Here's how your planned schedule looks based on the order you have selected the shows:
</Text>
<View style={styles.container}>
<Table borderStyle={{ borderWidth: 2, borderColor: '#c8e1ff' }}>
<Row data={state.tableHead} style={styles.head} textStyle={styles.text} />
<Col data={state.tableWeeks} />
<Col data={state.tableData} />
</Table>
</View>
);
}
}
const TVSHOWIMAGETITLES=[
抢劫钱财,破坏者,
抢劫钱财,破坏者,
抢劫钱财,破坏者,
抢劫钱财,破坏者,
抢劫钱财];
类HashTablesScreenTwo扩展React.Component{
建造师(道具){
超级(道具);
此.state={
五个显示:this.props.route.params.selectedShows,
桌面:[“周”,“电视节目”],
表周:[1,2,3,4,5],
tableData:[]
}
}
renderTableData(){
const jsxArray=this.state.tableWeeks.map((i)=>{this.renderTVShowImageTitle(i-1)})
console.log(jsxArray)
console.log(this.state.tableWeeks)
返回{
tableData:jsxArray
}
}
renderTVShowImageTitle(一){
设index=this.state.fiveShows[i];
返回(
1}
/>
)
}
render(){
const state=this.state;
{this.renderTableData()}
返回(
因为你雄心勃勃,
你已经决定以每周一场的速度疯狂观看这些节目。
以下是根据您选择的放映顺序,您的计划时间表的外观:
);
}
}
如果有人能指出我做错了什么,我将不胜感激。谢谢 您需要从map函数中删除大括号,如下所示:
constjsxarray=this.state.tableWeeks.map((i)=>this.renderTVShowImageTitle(i-1))
或使用返回语句:
constjsxarray=this.state.tableWeeks.map((i)=>{
返回此.renderTVShowImageTitle(i-1)
})