【发布时间】:2021-04-30 04:16:44
【问题描述】:
我正在使用 select-react 库 --> https://react-select.com/home
我已设法将选项映射到 itemList 中我需要的单个项目。下拉菜单确实注册了所选选项,但我的最终目标是让我的条形图呈现所选选项的正确数据。
/**
* Produces a filter list for item sales cards
* @param {*} props
* @returns the filter list of item names along with their ids
*/
export const ItemSelection = (props) => {
const { onChangeValue, itemList } = props;
if (itemList.length === 0) return <></>;
return (
<UncontrolledDropdown>
<Select
options={itemList.map((item) => {
return {
label: item.name,
value: item,
key: item.itemID,
};
})}
onChange={(item)=>onChangeValue(item)}
placeholder="ITEM"
/>
</UncontrolledDropdown>
);
};
这里使用了itemSelection:
const [itemID = '1', setItemID] = useState('1');
const [itemName = '', setItemName] = useState('');
const [itemListID = [], setItemListID] = useState([]);
<ItemSelection
onChangeValue={(item) => {
setItemID(item.itemID);
setItemName(item.name);
}}
itemList={itemListID}
/>
onChangeValue 是将所选选项注册到条形图的选项。无论如何要映射 onChangeValue 吗?
【问题讨论】:
标签: javascript reactjs react-select