Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
125
rated 0 times [  127] [ 2]  / answers: 1 / hits: 149877  / 9 Years ago, tue, february 17, 2015, 12:00:00

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 line 13 column 15) Line: 52 Column:3




With this code



var GridRow = React.createClass({
render: function() {
var row;

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

return (
<tr>
{row}
</tr>
);
}
});


The render part seems to be really limited in how it can be used?


More From » reactjs

 Answers
12

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 <td className={cell.Meta.HTMLClass} key={i}>{cell.Text}</td>;
}
else {
return <td className={cell.Meta.HTMLClass} key={i}>{cell.Text}</td>;
}

}.bind(this));

[#67790] Sunday, February 15, 2015, 9 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
jeffn

Total Points: 559
Total Questions: 81
Total Answers: 103

Location: Spain
Member since Thu, Dec 23, 2021
2 Years ago
;