You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何在Ant Design React中禁用Select下拉框的选项?

解决Ant Design Select根据IsSubmitted状态禁用选项的问题

你当前的代码逻辑是当IsSubmitted不等于1时禁用选项,和需求刚好相反。只需要调整Option组件的disabled判断条件,就能实现「IsSubmitted等于1时禁用对应选项」的效果:

<Select
  // disabled={disbledOption}
  showSearch
  mode="multiple"
  allowClear
  optionFilterProp="children"
  placeholder="Vendors"
  options={vendorsMaster}
  style={{ maxHeight: '70px', overflowY: 'auto' }}
  filterOption={(input: string, option: any) =>
    filterOption(input, option)
  }
>
  {props.vendorTagVal &&
    props.vendorTagVal.map((opt: any) => (
      <Option
        // 把判断逻辑从 !== 改成 ===,实现IsSubmitted=1时禁用
        disabled={opt.IsSubmitted === 1}
        key={opt.VendorID}
        value={opt.VendorID}
      >
        {opt.VendorName}
      </Option>
    ))}
</Select>

额外注意

  • 确认props.vendorTagVal中的每个对象都存在IsSubmitted字段,且字段值为数字类型;如果是字符串类型(比如"1"),需要把判断改成opt.IsSubmitted === '1'
  • 如果vendorsMaster是数据源数组,同时使用了options属性和手动渲染Option,需要确保两者的逻辑一致,避免出现显示不一致的问题

内容的提问来源于stack exchange,提问作者Binni kumari

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.16 09:22:02