Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cascader 组件 异步加载在受控形态下,无法选中数据 #1875

Closed
GleanCoder1116 opened this issue Aug 16, 2021 · 0 comments · Fixed by #1876
Closed

Cascader 组件 异步加载在受控形态下,无法选中数据 #1875

GleanCoder1116 opened this issue Aug 16, 2021 · 0 comments · Fixed by #1876
Labels
3.x bug Something isn't working comp:cascader

Comments

@GleanCoder1116
Copy link
Collaborator

import React from 'react'
import Cascader from '@hi-ui/hiui/es/cascader'

class Demo extends React.Component {
  constructor () {
    super()
    this.state = {
      options: []
    }
  }
  render(){
    return(
      <Cascader
        onChange={(value)=>{
          console.log('on change', value)
        }}
        data={this.state.options}
        style={{ width: 240 }}
        defaultValue={['电视','小米电视4C']}
        onOpen={()=>{
          const {options} = this.state
          if(options.length === 0){
            setTimeout(()=>{
              this.setState({
                options: [
                  {
                    id: '手机',
                    content: '手机',
                    children: [
                      {
                        id: '手机2',
                        content: '手机2',
                      }
                    ]
                  },
                  {
                    id: '平板',
                    content: '平板'
                  },
                  {
                    id: 'mix',
                    content: 'Mix',
                    children: []
                  }
                ]
              })
            }, 2000)
          }
        }}
        onActiveItemChange={values=>{
          if(values[0] == 'mix') {
            setTimeout(()=>{
              const _options = this.state.options
              _options[2].children = [
                {
                  id: 'mix1',
                  content: 'Mix1'
                },{
                  id: 'mix2',
                  content: 'Mix2'
                },{
                  id: 'mix3',
                  content: 'Mix3'
                }
              ]
              this.setState({
                options: _options
              })
            }, 1000)
          }
        }}
      />
    )
  }
}
@GleanCoder1116 GleanCoder1116 added the bug Something isn't working label Aug 16, 2021
GleanCoder1116 pushed a commit that referenced this issue Aug 19, 2021
GleanCoder1116 pushed a commit that referenced this issue Aug 19, 2021
@GleanCoder1116 GleanCoder1116 linked a pull request Aug 19, 2021 that will close this issue
@Flcwl Flcwl mentioned this issue Sep 28, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
3.x bug Something isn't working comp:cascader
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants