When building an form that takes user input of number ratings on a set of items evaluated by a set of attributes, how can I set their index accordingly and what's the best way to capture/update all the inputs in the state such that I can compare their total later? The code can be found below or in sandbox Thanks for any inputs.
import React, { Component } from "react";
export default class Compare extends Component {
constructor(props) {
super(props);
this.state = {
items: props.items,
attributes: props.attributes,
itemAttributeScoreArray: [],
eval: null
};
}
_onChangefor = (index1, index2) => event => {
console.log(event.target.value);
};
render() {
return (
<div>
<table
className="Table"
style={{
margin: "0 auto"
}}
>
<thead>
<tr>
<th>Compare</th>
<th>{this.state.items[0]}</th>
<th>{this.state.items[1]}</th>
</tr>
</thead>
<tbody>
{this.state.attributes.map((attribute, index1) => (
<tr>
{attribute}
{this.state.items.map((item, index2) =>
<td>
<input
key = {index1+''+index2}
type="number"
onChange={this._onChangefor((index1, index2))}
/>
</td>)}
</tr>
))}
</tbody>
</table>
</div>
);
}
}
