多个搜索选择下拉列表

时间:2018-04-06 11:25:57

标签: javascript reactjs semantic-ui-react

请告诉我,如何在多重搜索选择下拉列表中设置defaultValue?我试图在文档中设置对象数组,但是我没有收到我想要的内容

constructor(props) {
  super(props);

  this.state = {
     specs: [],
     doctorSpecs: []
  }

  this.profileService = new ProfileService();
  this.addSpecializationsService = new SpecializatoinsService();
}

componentWillMount() {
 this.profileService.getProfileInformation()
  .then((res) => {
   this.setState({
    profile: res.data,
    consultationFees: res.data.consultation_fees,
    mpdbRegistrationNumber: res.data.mpdb_registration_number,
    qualification: res.data.qualification,
    experienceYears: res.data.experience_years,
    doctorSpecs: res.data.specializations.map((elem, index) => {
      return {key: index, value: elem.id, text: elem.name}
    })
  })
})

this.addSpecializationsService.getSpecializationsList("", (res) => {
  console.log(res);
  this.setState({
     specs: res.data.body.map((elem, index) => {
       return {key: elem.id, value: elem.id, text: elem.name}
     })
   })
 });
} 

// other nessesary code

// component where must be this.state.doctorSpecs
<Dropdown 
    className='profile-specs'
    placeholder='Skills' 
    fluid multiple selection search 
    options={this.state.specs} 
    onChange={this._onChangeSpecs}
    value={this.state.doctorSpecs}
    onSearchChange={this._getListSpecs}/>

我希望在渲染组件之后,在此下拉列表中显示值数组 我试图使用value,defaultValue,但它不起作用

1 个答案:

答案 0 :(得分:0)

我发现了一个问题。 我不得不转移到数组而不是对象,而是来自此对象的文本值