嵌套Map循环返回不返回任何内容 [英] Nested Map loops return not returning anything

查看:107
本文介绍了嵌套Map循环返回不返回任何内容的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个嵌套的地图循环(外部用于每天渲染,内部用于在一天之内渲染元素.我遇到的问题是,返回块中没有返回任何内容.首先,我不确定为什么只有一个循环(一天之内的元素)没有返回任何东西,其次,有什么方法可以合并循环吗?

I have a nested map loop (the outer for rendering each day, and the inner for rendering the elements within the day. The issue I'm having, is that nothing is being returned in the return block. The area where there should be something rendering, there is nothing there. First of all, I'm not sure why nothing is being returned, when I only had one loop (the elements within the day one). Second, is there any way to maybe combine the loops?

{
  daysArray.map(days => {
    var dayState = eval('global.that.state.' + days);
    var dayStateArray = Object.values(dayState);
    dayStateArray.map(i => {
      return ( 
        <Card 
          style={{ justifyContent: 'center', alignItems: 'center' }}
          key = {i.id}
        >
          <Text key={i.name}>{i.name.replace('&amp;', '&')}</Text>
          <Text key={i.start_timestamp}>Starting: {i.start_timestamp</Text> 
          <Text key={i.end_timestamp}>Ending: {i.end_timestamp}</Text
        </Card>
      )
    })
  })
}

推荐答案

之所以没有呈现任何内容,是因为第一张地图没有返回任何内容.您将需要返回嵌套地图以渲染元素.

Reason nothing is being rendered is because nothing is being returned from first map. You would need to return nested map for elements to be rendered.

{
  daysArray.map(days => {
    var dayState = eval('global.that.state.' + days);
    var dayStateArray = Object.values(dayState);
    return dayStateArray.map(i => {
      return ( 
        <Card 
          style={{ justifyContent: 'center', alignItems: 'center' }}
          key={i.id}
        >
          <Text key={i.name}>{i.name.replace('&amp;', '&')}</Text> 
          <Text key={i.start_timestamp}>Starting: {i.start_timestamp}</Text> 
          <Text key={i.end_timestamp}>Ending: {i.end_timestamp}</Text> 
        </Card>
      )
    })
  })
}

这篇关于嵌套Map循环返回不返回任何内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆