问题
I am getting an error from react js when I execute this code snippet:
<TableBody>
{ (data.length > 0) ? (
data.map((x, i) => row(
x,
i,
formColumns,
handleRemove,
handleSelect,
editIdx
))) : (<TableRow><TableCell colSpan={`${cols}`}>No Data</TableCell></TableRow>)}
</TableBody>
The value of 'data' is an empty array [], which SHOULD return a length of 0 But it passes the length test somehow.
Instead I get an error 'data.map is not a function'.
I am trying to insert:
console.log('data = ' + JSON.Stringify(data, null, 2) + '.'))
in the code somewhere, so I can see what it's doing. When I check the data GOING IN to the Table, it's = []. So why is the length not working, and what do I need to do to place javascript code inside a set of material-ui elements? Any help would be much appreciated!
回答1:
Something like:
{ console.log('data = ' + JSON.Stringify(data, null, 2) + '.')) }
来源:https://stackoverflow.com/questions/62751068/how-to-insert-a-console-log-in-material-ui-elements-to-verify-object-array-value