Welcome to WuJiGu Developer Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
314 views
in Technique[技术] by (71.8m points)

antd中无法手动设置select选中值?

在我收到一条其他组件处理好的数据后,我想把它的值直接设置为一个Option,并且自动选中它。
我应该如何操作?

这里是沙盒地址:https://codesandbox.io/s/runtime-violet-0st76?file=/src/index.js

(我试过在Form.Item上设置defaultValue/value,以及在select上设置value,不过都失效了)

万分感谢!


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

我大概找到了问题,当使用了Form.Item并指定了name属性时,就变成了受控组件。设置值要在Form上做,Form.Item或其包裹的元素上的值的设置会被忽略
图片.png


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to WuJiGu Developer Q&A Community for programmer and developer-Open, Learning and Share
...