如何使用MongoDB使单选按钮自动签入编辑页面?



我有 2 页,第一个是添加页面,第二个是编辑页面。在添加页面中,我有一个无线电button for gender,我将信息存储在MongoDB中。在编辑页面中,我尝试自动选择单选按钮,但它不起作用。这是我的编辑页面代码:

const gender = document.querySelector('input[name = gender]:checked').value;
e.preventDefault();
Meteor.call(
'employee.update',
this.props.match.params.id,
gender
);
return alert("Employee Information Has Been Updated!");
}

renderEmployeeEdit() {
return this.state.employees.map(employee => {
return (
<div key={employee._id}>
<form onSubmit={this.onSubmit.bind(this)}>
<input type="radio" name="gender" value="Male"/>Male <br/>
<input type="radio" name="gender" value="Female"/>Female
</form>
</div>
);
});
}

使用defaultChecked属性,可用于<input type="radio">

您可以使用表单控件名称,并且可以在组件TS文件中的表单中定义它,当表单对象填充所选记录的值时,您应该从单选按钮中删除checkedc,同时编辑它将显示为选中,以真实为准

<div class="form-group row">
<label class="col-md-4 col-form-label">Is Taxable</label>
<div class="col-md-8">
<div class="custom-control custom-radio custom-control-inline">
<input type="radio" class="custom-control-input" id="isTaxableYes" formControlName="isTaxable" [value]="true">
<label class="custom-control-label" for="isTaxableYes">Yes</label>
</div>
<!-- Default checked -->
<div class="custom-control custom-radio custom-control-inline">
<input type="radio" class="custom-control-input" id="isTaxableNo" formControlName="isTaxable" [value]="false">
<label class="custom-control-label" for="isTaxableNo">No</label>
</div>
</div>
</div>

最新更新