我需要创建一个const组件来呈现选项及其选项,但是由于代码返回的选项没有任何选项,因此无法呈现选项字段。问题在哪里?无法从const数组映射中渲染
谢谢你的建议。
import React from "react";
const FilterSelect = (props) => {
const {title, name, selectedValue, optionsValue, onChange} = {...props};
const renderOptions = (optionsValue) => {
optionsValue.map((optionValue, i) =>
<option value={optionValue.value} key={i}>{optionValue.name}</option>
);
};
return (
<div className="filters-content-block">
<h3 className="filters-subtitle">{title}</h3>
<select className="sl sl-fullwidth" onChange={onChange} required>
{renderOptions}
</select>
</div>
);
};
export default FilterSelect;
在我看来,这是最好的解决办法,所以我用它更改我的代码。谢谢! – Aitor