6

I have:

var model =[{
    name:  "Reg",
    value: "Reg"
},{
    name:  "26.0000",
    value: "26.0000"
}];

...

generateRows(){
    var jsxResult = (
        <tr className="performRowStyle">
            {
                for(var i=0, rowCount = model.length; i < rowCount; i++ ) {
                    var thisRow = model[i];
                    console.log("columnData.name = " + thisRow.name + "columnData.value = " + thisRow.value);
                    jsxResult += (
                          <td className="performColumnStyle">
                              <span className="performColumnDataStyle">{thisRow.value}</span>
                          </td>
                    );
                }
            }
          </tr>
    );

    return jsxResult;
}

Webpack reports a module build failure. It's rejecting most of the JavaScript I put in the jsxResult. This works, but fails to do anything useful:

generateRows(){
    var jsxResult = (
      <tr className="performRowStyle">
        {
            this.test()

        }
      </tr>
    );

    return jsxResult;
  },

Why am I getting an error? How can I generate this data dynamically?

Majid Parvin
  • 4,499
  • 5
  • 29
  • 47
P.Brian.Mackey
  • 43,228
  • 68
  • 238
  • 348
  • @FelixKling - Note that I also tried `var i = 0;` in place of `this.test()` which also failed. – P.Brian.Mackey Jun 15 '16 at 16:21
  • 2
    You can only put **expressions** inside `{...}` in JSX (or in other words, constructs that produce a value). `var ...` however is a *statement*. JSX is converted into function calls. `
    {...}
    ` becomes `React.createElement('div', null, ...)`. You wouldn't be able to write `React.createElement('tr', {className: 'performRowStyle'}, var i = 0)`. For the same reason you cannot use a `for` loop either, as explained in the duplicate.
    – Felix Kling Jun 15 '16 at 16:22
  • @FelixKling - Got it. It'll take a bit to absorb the material. It feels like you are right. I'll close it out once I have something working. – P.Brian.Mackey Jun 15 '16 at 16:26

0 Answers0