n4kz / react-native-material-dropdown

Material dropdown with consistent behaviour on iOS and Android
Other
732 stars 597 forks source link

is it possible to get an array of json to displaying it on dropdown list? #93

Closed flixyudh closed 6 years ago

flixyudh commented 6 years ago

I've an example json using state like this:

this.state = {"diagnosis": {
        "type": [
          "Oncology",
          "Hip And Knee"
        ],
        "kode": [
          "123",
          "321",
          "3232",
          "1231"
        ],
        "PrimaryCat": [
          "contoh1",
          "contoh2",
          "contoh3"
        ]}
}

render() {
    return (
      <View>
        <Dropdown
          label="testing"
          data={this.state.diagnosis.type}
        />
        <Dropdown
          label="kode"
          data={this.state.diagnosis.kode}
        />
      </View>
    );
  }

the result of dropdown is not showing the array text,

here's the example screen :

image

am i wrong?

danisbubblesdad commented 6 years ago

The object format is [{value: [insert string you want to show in dropdown here]},...]. This tool will not work out of the box with the format that you've specified.

So in your example, you would need to map the JSON to [{value: "Oncology"},{value: "Hip And Knee"}].

There is a valueExtractor function built-in for this specific purpose.