gpt4 book ai didi

How to set values by default using checkboxes? [closed](如何使用复选框设置默认值?[已关闭])

转载 作者:bug小助手 更新时间:2023-10-26 20:25:57 26 4
gpt4 key购买 nike




I'm using a Map to store the state of my checkboxes. My current component has 3 sections. In each section I have checkboxes. I would like to set these values by default:

我正在使用地图来存储我的复选框的状态。我当前的组件有3个部分。在每个部分,我都有复选框。我想在默认情况下设置这些值:


const defaultOptions = [
{ label: "Mark", value: "mark" },
{ label: "Steve", value: "steve" },
{ label: "Paul", value: "Paul" }
];

How can I use this array and set values by default? Thanks in advance!

如何使用此数组并在默认情况下设置值?提前谢谢!


Here's a live DEMO

这是一个现场演示


更多回答
优秀答案推荐

You can aggregate the values in the array into a Map based on the post label.

您可以将数组中的值聚合到基于POST标签的Map中。


setCheckboxStates(defaultOptions.reduce((acc, curr) => {
const key = someJson.find(p => p.fields.some(f => f.name === curr.label)).label;
if (!acc.has(key)) acc.set(key, []);
acc.get(key).push(curr);
return acc;
}, new Map()));

更多回答

Demo

演示

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com