Advertisement
Guest User

Untitled

a guest
Jun 16th, 2019
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.40 KB | None | 0 0
  1. constructor(props) {
  2. super(props);
  3. this.state = {
  4. objects: {
  5. name: '',
  6. mass: [
  7. {
  8. img: '',
  9. count: '1', // Это первый инпут
  10. countMass: '2' // Это состояние второго инпута
  11. },
  12. {
  13. img: '',
  14. count: '1', // Это первый инпут
  15. countMass: '2' // Это состояние второго инпута
  16. },
  17. };
  18. };
  19.  
  20. this.handleInputChange = this.handleInputChange.bind(this);
  21. }
  22.  
  23. {this.mass.map((variant, index) => {
  24. return (
  25. <div key={index}>
  26. <Input name={"count" + index} onChange={this.handleInputChange} value={variant.count} />
  27. <Input name={"countMass" + index} onChange={this.handleInputChange} value={variant.mass}/>
  28. </div>
  29. )
  30.  
  31. handleInputChange(event) {
  32. let objects = {...this.state.objects}
  33. const target = event.target;
  34. const value = target.value;
  35. const name = target.name;
  36.  
  37. this.setState({
  38. objects: {
  39. ...objects,
  40. mass: [
  41. [name]: value
  42. ]
  43. }
  44. });
  45. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement