How to use if within a map return?

前端 未结 2 500
一个人的身影
一个人的身影 2021-01-31 16:54

I need to generate diffrent reactJS code based on datamodel but I get

In file \"~/Scripts/Grid.jsx\": Parse Error: Line 13: Unexpected token if (at lin

2条回答
  •  失恋的感觉
    2021-01-31 17:15

    You put return statement inside if clause like so:

        row = this.props.cells.map(function(cell, i) {
    
            if(cell.URL != null && cell.URL.length > 0){
                return {cell.Text};        
            }
            else {
                return {cell.Text};
            }
    
        }.bind(this));
    

提交回复
热议问题