【问题标题】:return _.map(this.state.categoria, categoria => { function() } is not returningreturn _.map(this.state.categoria, categoria => { function() } 没有返回
【发布时间】:2018-09-22 17:57:24
【问题描述】:

我对使用 .map() 的函数的对象有问题,如果我使用它可以工作的代码,但如果我输入一个函数则无法正常工作。示例:

if(this.state.cat){ 
   return _.map(this.state.cat, categoria => {

        if(this.state.search_receive){
          somecode...

        }else {
          this.retornaItens(categoria);
          //if I put the <p>code here</p> it works
        }

    });


    retornaItens = (categoria) =>{
     return (  <p>code..</p> ); }

【问题讨论】:

  • “不工作”是什么意思?
  • 如果我在函数内部使用代码,则不会返回,但如果我直接使用代码(例如

    code

    ),它可以工作..
  • 我发现了问题,我在哪里调用了我需要返回的函数:return this.retornaItens(categoria);

标签: javascript reactjs typescript react-native


【解决方案1】:

你需要像这样定义方法:

retornaItens = (categoria) => () => {

更多信息,请查看我的另一个post

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-12-18
    • 1970-01-01
    • 2017-05-19
    • 2014-04-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-11-19
    相关资源
    最近更新 更多