简体   繁体   English

函数未返回,但 console.log 显示内容

[英]A function is not returning, but console.log is showing the content

I am making a function that will render the information of fees in each installment(key is equal to installment1, card[1][key] is the value, like a float 2.5), but my function is not returning!我正在制作一个函数,它将呈现每一期的费用信息(key 等于 installment1,card[1][key] 是值,就像一个浮点数 2.5),但我的函数没有返回! The console.log is working perfectly, anyone can give me an insight?! console.log 运行良好,任何人都可以给我一个见解?!

export function returnInstallmentsWithFee(card, fee) {
   Object.keys(card[1]).forEach(function (key) {
      console.log('test', key, card[1][key])
      return (
        <div>
          {key}:{card[1][key]}
         </div>
      )
   })
}
  1. your top level function ( returnInstallmentsWithFee ) doesn't have a return satatement;您的顶级函数 ( returnInstallmentsWithFee ) 没有返回值;
  2. forEach doen't return anything, you may want to use .map() forEach不返回任何内容,您可能需要使用.map()
export function returnInstallmentsWithFee(card, fee) {
      return Object.keys(card[1]).map(function (key) {
        console.log('test', key, card[1][key])
        return (
          <div>
            {key}:{card[1][key]}
          </div>
        )
      })
    }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM