我正在开发一个项目,这是React的新项目。我已经从以前实现的下拉列表中复制了一个下拉列表。
{/* Previously Implemented Code */}
<Table.Row>
<Table.Cell>Planned Project Type</Table.Cell>
</Table.Row>
<Table.Row>
<Table.Cell ><PtInputConditionTab whichInput="firsttb" inputType="hwy" name="PlannedProjType" disabled value={typeOptions[this.state.PlannedProjType > 4 ? 0 : this.state.PlannedProjType].label}
onChange={this.onInputChange} />
</Table.Cell>
<Table.Cell ><PtSelect options={typeOptions.slice(0,5)}
onChange={this.onChangeDropdown} disabled={this.props.disabled} defaultVal={this.state.PlannedProjTypeOver} name="PlannedProjTypeOver" /></Table.Cell>
</Table.Row>
{/* Previously Implemented Code Ends */}
{/* Previously implemented code copied */}
<Table.Row>
<Table.Cell>Planned Project Type</Table.Cell>
</Table.Row>
<Table.Row>
<Table.Cell ><PtInputConditionTab whichInput="firsttb" inputType="hwy" name="PlannedProjType" disabled value={typeOptions[this.state.PlannedProjType > 4 ? 0 : this.state.PlannedProjType].label}
onChange={this.onInputChange} />
</Table.Cell>
<Table.Cell ><PtSelect options={typeOptions.slice(0,5)}
onChange={this.onChangeDropdown} disabled={this.props.disabled} defaultVal={this.state.PlannedProjTypeOver} name="PlannedProjectSurfaceTypeOver" /></Table.Cell>
</Table.Row>
{/* Previously Implemented Copied Code Ends */}
当我在PtSelect标记的第二部分中更改名称属性时,下拉列表不会显示所选值。即使单击下拉列表中的其他值,它也始终显示下拉列表的第一个值。只是为了让您知道,当我为选定的值执行console.log()时,它正在选择这些选项,而只是不显示所选的那个。 为了确保您理解正确,我正在尝试更改注释行“先前实现的代码已复制”中的部分的名称。
答案 0 :(得分:0)
我把它修好了。它只是我错误地传递的defaultVal属性参数。