React中使用ant.design的form.item里tabs里写select多选框,初始化不生效

ant.design文档里的案例:

 const children: React.ReactNode[] = [];
  for (let i = 10; i < 36; i++) {
    
    
    children.push(<Option key={
    
    i.toString(36) + i}>{
    
    i.toString(36) + i}</Option>);
  }

解决方案:
把Options的形式替换成形式

React.createElement(
      Select.Option,
      {
        label,
        value,
        key: key || value,
      },
      label
    );
  });

修改后的案例:

  const children: React.ReactNode[] = [];
  for (let i = 10; i < 36; i++) {
    
    
    let t = i.toString(36) + i
    children.push(
      React.createElement(
        Select.Option,
        {
    
    
          label: t,
          value: t,
          key: t || value,
        },
        t
      )
    );
  }

猜你喜欢

转载自blog.csdn.net/qq_41160739/article/details/127429327
今日推荐