Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/80.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
html输入在添加时不可编辑";“价值”;参数_Html_Reactjs_Meteor - Fatal编程技术网

html输入在添加时不可编辑";“价值”;参数

html输入在添加时不可编辑";“价值”;参数,html,reactjs,meteor,Html,Reactjs,Meteor,我和React 16一起工作。我有一个输入字段,需要从我的数据库中填充一个值,并且我需要它是可编辑的 如果我使用: <FormControl type="text" ref="price" id="precio" value={this.state.precioVenta} /> 输入字段填充值,但不允许我编辑。我试过了 <FormControl type="text" ref="price" id="precio" defaultValue={this.state.pr

我和React 16一起工作。我有一个输入字段,需要从我的数据库中填充一个值,并且我需要它是可编辑的

如果我使用:

<FormControl type="text" ref="price" id="precio" value={this.state.precioVenta} />

输入字段填充值,但不允许我编辑。我试过了

<FormControl type="text" ref="price" id="precio" defaultValue={this.state.precioVenta} />


但它不会填充处理更改所需的值。如果您只需设置该值,它将始终设置为:

<FormControl 
  type='text'
  name='precio' 
  defaultValue={this.state.precioVenta}
  onChange={this.handleChange.bind(this)}
/>

handleChange(event) {
    let fieldName = event.target.name;
    let fieldVal = event.target.value;
    this.setState({...this.state, [fieldName]: fieldVal})
}

手变(活动){
让fieldName=event.target.name;
让fieldVal=event.target.value;
this.setState({…this.state,[fieldName]:fieldVal})
}

是否有理由不使用占位符而不是值<代码>

它看起来像一个典型的状态更新问题。你在哪里更新你的状态?我想您需要手动处理输入更改:

<FormControl type="text" value={this.state.precioVenta} onChange={this.handlePrecioChange} />
不要忘记在组件的构造函数上绑定组件的实例上下文,以使处理程序中的
正常工作:

constructor {
  this.handlePrecioChange = this.handlePrecioChange.bind(this);
}
constructor {
  this.handlePrecioChange = this.handlePrecioChange.bind(this);
}