React Js将数组数据发布到api

时间:2018-05-28 08:37:52

标签: javascript arrays json reactjs react-redux

我是新手。 如何使用rest api发布数组数据。此表单数据从数据库循环。

我有这样的代码(Createreport.js):

  render() {
  const { data } = this.state;
  return (
       <form onSubmit={this.reportUpdate} method="post">
          <Input type="text"
                 onChange={this.handleInputChange} 
                 value={this.state.namaCustomer} 
                 name="namaCustomer" />

          {data.map((item, index) => (
          <Col xs="12" sm="4" key={item.product_id}>
             <Label htmlFor="text-input">Quantity :</Label>
             <Input type="number" id="text-input" onChange={this.handleQtyChange.bind(this, index)} value={this.state.qty['']} name={`qty[]${index}.qty`} placeholder="Quantity" />
             <Input type="number" onChange={this.handleProdChange.bind(this, index)} defaultValue={item.product_id} name={`product_id[]${index}.product_id`} />

              <Label htmlFor="text-input">Notes :</Label>
              <Input type="textarea" onChange={this.handleNoteChange.bind(this, index)} value={this.state.note['']} name={`note[]${index}.note`} rows="4"
                             placeholder="Content..." />
          </Col>
          ))}

          <Col xs="12">
            <Input 
                  type="submit" onClick={this.reportUpdate} value="Submit"/>
          </Col>
    );
  }
}

export default Createreport;

0 个答案:

没有答案
相关问题