简体   繁体   English

如何在反应本机的多个选择下拉字段中过滤数组值

[英]How to filter array value in multiple Select drop down field in react native

Suppose the bellow array values I have an array of lgas.假设波纹管数组值我有一个 lgas 数组。 Below there are 3 select fields, Lga, state and country.下面有 3 个选择字段,Lga、州和国家。 I have to get drop down value in lga field.我必须在 lga 字段中获得下拉值。 If I select any value in the lga drop down then the value present in the same element should automatically appear in the state and country dropdown.如果我在 lga 下拉列表中选择任何值,则同一元素中存在的值应自动出现在州和国家/地区下拉列表中。

eg.例如。 If I select code BNG in lga then country India should be in country drop down and Karnataka value in state should display.如果我在 lga 中选择代码 BNG,那么国家印度应该在国家下拉列表中,并且应该显示卡纳塔克邦的值。 Please help.请帮忙。

 // Array Value  
      masterData:
        lga: Array(1)
        0:
        code: "BNG"
        name: "BANGALORE"
        state:
        code: "KA"
        name: "KARNATAKA"
        __typename: "TroubleTicketMasterCode"
        __proto__: Object
       country:
        code: "IND"
        name: "INDIA"
        __typename: "TroubleTicketMasterCode"
        __proto__: Object 
        __typename: "Lga"
        1:
        code: "1234"
        name: "Mangalore"
        state:
        code: "700"
        name: "PARIS"
        __typename: "TroubleTicketMasterCode"
        __proto__: Object
       country:
        code: "NG"
        name: "NIGERIA"
        __typename: "TroubleTicketMasterCode"
        __proto__: Object
        __typename: "Lga"

    // Select field 

                        <SelectField
                            label="Lga"
                            node="lga"
                            options={lga}
                            value={}
                            onChange={this.lgachanges}
                            that={this}
                            setIcon={true}

                          />

                          <SelectField
                            label="State"
                            options={}
                            value={}
                            node="state"
                            onChange={}
                            that={this}
                            setIcon={true}

                          />

                          <SelectField
                            label="Country"
                            options={}
                            value={}
                            node="country"
                            onChange={}
                            that={this}
                            setIcon={true}

                          />

Thanks谢谢

lgachanges = event => {
  const temp = lga.find(element =>  element.code === event.target.value)

  this.setState({
    lga: temp.name,
    country: temp.country.name,
    state: temp.state.name,
  })
}

In each Select:在每个选择中:

 value={this.state. ...} //lga, country, state   

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM