我有对象数组,我正在通过.map()
函数填充数据,我想默认选择下拉列表的第一个值,还需要获取第一个选项属性值。我非常努力,但没有找到具体的解决方案。有人可以帮我实现目标吗?
代码
<select className="form-control input-box" {...input} required>
<option>Select Manager</option>
{managerList.map((item, index) => (
<option
value={item.id}
managerZoneId={item.zoneId}
key={item.id}
>
{item.firstName + " " + item.lastName}
</option>
))}
</select>
<select className="form-control input-box" {...input} required
defaultValue={managerList[0].id} // Add this line
>
<option>Select Manager</option>
{managerList.map((item, index) => (
<option
value={item.id}
managerZoneId={item.zoneId}
key={item.id}
>
{item.firstName + " " + item.lastName}
</option>
))}
</select>