【发布时间】:2018-11-02 04:20:51
【问题描述】:
我的状态:
this.state = {
name: '',
subCatagory: [{ name: '', price: '', customize: [] }],
};
我在 react.js 中的表单:
{this.state.subCatagory.map((subCatagory, idx) => (
<div className="subCatagory" key={idx}>
<input
type="text"
placeholder={`Enter Dish #${idx + 1} name`}
value={subCatagory.name}
onChange={this.handlesubCatagoryNameChange(idx)}
/>
<input
type="number"
placeholder={`subCatagory #${idx + 1} price`}
value={subCatagory.price}
onChange={this.handlesubCatagoryPriceChange(idx)}
/>
<button
type="button"
onClick={this.handleRemovesubCatagory(idx)}
className="small"
>
Delete
</button>
<button type="button" onClick={this.addNewCust(idx)} className="small">
is cust availble?
</button>
{subCatagory.customize.map((customize, custIdx) => (
<div key={custIdx}>
<input
type="text"
placeholder={`subCatagory #${custIdx + 1} price`}
value={customize.name}
onChange={this.handlesubCatagoryChange(
idx,
'customize',
custIdx
)}
/>
</div>
))}
</div>
))}
我想每次在输入handlesubCatagoryChange 中更新值并且我的表单是动态表单时进行更新。这里我获取了第一个地图的索引,然后是第二个地图的索引,但无法更新状态反应
【问题讨论】:
标签: javascript reactjs