需要在ANTD中进行默认检查中的广播按钮

发布于 2025-01-22 09:17:41 字数 1019 浏览 2 评论 0原文

我有一个无线电按钮组,其中包含来自数组的动态数据。 这是代码:

<Radio.Group
    options={uniqueRadioElements}
    onChange={onCategorySelect}
    value={selectedCategory}
    optionType="button"
    buttonStyle="solid"
    className="select-category"
    checked="true"
/>
<Col span={24}>
    <div className="professionals-wrapper">
        {arrayOfElements
            .filter((item) => item.category === selectedCategory)
            .map((item) => {
                return (
                    <div className="details-of-categories">
                        <Image
                            src="/images/clinic.png"
                            preview={false}
                            alt="photo 4"
                        />
                        <h3>{item.title}</h3>
                        <Rate defaultValue={4} disabled />
                    </div>
                )
            })}
    </div>
</Col>

我想将其默认检查为无线电按钮组的特定元素

I have a Radio Button Group with dynamically data coming from an array.
Here's the code :

<Radio.Group
    options={uniqueRadioElements}
    onChange={onCategorySelect}
    value={selectedCategory}
    optionType="button"
    buttonStyle="solid"
    className="select-category"
    checked="true"
/>
<Col span={24}>
    <div className="professionals-wrapper">
        {arrayOfElements
            .filter((item) => item.category === selectedCategory)
            .map((item) => {
                return (
                    <div className="details-of-categories">
                        <Image
                            src="/images/clinic.png"
                            preview={false}
                            alt="photo 4"
                        />
                        <h3>{item.title}</h3>
                        <Rate defaultValue={4} disabled />
                    </div>
                )
            })}
    </div>
</Col>

I want to make it default checked for a specific element of Radio Button Group

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

誰認得朕 2025-01-29 09:17:41

这是我的解决方案

<Form.Item
   name="type"
   initialValue={1}
>
   <Radio.Group>
<Radio value={1}>off</Radio>
   </Radio.Group>
</Form.Item>

Here's my solution using with From

<Form.Item
   name="type"
   initialValue={1}
>
   <Radio.Group>
<Radio value={1}>off</Radio>
   </Radio.Group>
</Form.Item>
娇女薄笑 2025-01-29 09:17:41

您可以将DIP DEFAULT检查的Prop删除检查到所需的特定索引中。第一个示例是:

<input defaultChecked={index === 0} />

在您的情况下,我将删除检查值并添加默认值。

<Radio.Group 
  options={uniqueRadioElements} 
  onChange={onCategorySelect} 
  value={selectedCategory} 
  optionType="button" 
  buttonStyle="solid" 
  className="select-category" 
  defaultChecked={index === 0} /> 

You can add the prop defaultChecked to the specific index you want. An example for the first one would be:

<input defaultChecked={index === 0} />

In your case I would delete the checked value and add the defaultChecked.

<Radio.Group 
  options={uniqueRadioElements} 
  onChange={onCategorySelect} 
  value={selectedCategory} 
  optionType="button" 
  buttonStyle="solid" 
  className="select-category" 
  defaultChecked={index === 0} /> 
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文