【问题标题】:Update component in generic way以通用方式更新组件
【发布时间】:2020-04-01 19:07:35
【问题描述】:

这是我的Codesandbox

现在,当用户使用 e.target.textContent 在 selectList(antd 组件) 上选择一个项目时,我会更改标题。

有什么方法可以显示所有值,现在我只能显示一个选择列表值。

我想要这样的东西:value from first dropdown / value from second dropdown

<DropDown>
  <DropDown.DropDownTitle>
    This title will update after user selection // this should be updated when user select 
  </DropDown.DropDownTitle>
  <DropDown.DropDownBody>
    <Select
      defaultValue="lucy"
      style={{ width: 120 }}
      onChange={handleChange}
    >
      <Option value="jack">another</Option>
      <Option value="lucy">another 2</Option>
    </Select>
    <Select
      defaultValue="lucy"
      style={{ width: 120 }}
      onChange={handleChange}
    >
      <Option value="jack">another 3</Option>
      <Option value="lucy">another 4</Option>
    </Select>
  </DropDown.DropDownBody>
</DropDown>

【问题讨论】:

  • 你在哪里存储标题值?
  • @JMadelaine 在上下文 DropDownContext.js

标签: reactjs antd


【解决方案1】:

我可以看到您正在使用antd,我相信最好将Selectmultiple selection 一起使用,它会按照您想要的方式设置值。 这是他们的沙盒:https://codesandbox.io/s/cpive

【讨论】:

  • 感谢您的回答,我确实在 index.js 中使用了 antd
  • 如果这是你的正确答案,请将其标记为正确并放弃投票:)
  • 不,这不是正确的答案,也与我的问题无关
猜你喜欢
  • 2019-08-03
  • 1970-01-01
  • 2013-09-09
  • 2012-12-31
  • 2021-05-28
  • 2014-07-17
  • 1970-01-01
  • 2021-10-03
  • 1970-01-01
相关资源
最近更新 更多