constructor() {
   super();
    this.state = {
      highcourtname: [],
    }
  }

  getFromDatabase = () => {

    var that = this;
    db.transaction((tx) => {
      tx.executeSql('SELECT Distinct(Court_Name) FROM court_images', [], (tx, results) => {
        var len = results.rows.length;
        if (len > 0) {
          for (let i = 0; i < len; i++) {
            let rowall = results.rows.item(i);
            console.log(rowall);
            //this.setState({highcourtname: rowall.name})
          }

        }
      });
    });
  }

<DropDownPicker
    items={[
        {label: 'UK', value: 'uk'},
        {label: 'France', value: 'france'},
    ]} //how to get rowall value here??

    defaultValue={this.state.highcourtname}
    onChangeItem={item => this.setState({
        highcourtname: item.value
    })}
/>

I have used DropDown from 'react-native-dropdown-picker'; I want to display values from my sqlite db to dropview in react native. I am getting values from sqlite db, have console.log and checked it but dont know how to show in dropdown items above.

How to show "rowall" values in Items Dropdown???

How do I do that? If anybody could please help .

I am new in react native developement..

1

There are 1 best solutions below

3
On BEST ANSWER

Just set correctly your state and you're done

if (len > 0) {
   let rowall = []
   for (let i = 0; i < len; i++) {
        rowall.push({label: results.rows.item[i].name, value: results.rows.item[i].value});
   }
   this.setState({highcourtname: rowall})
}

and

<DropDownPicker
    items={this.state.highcourtname}

    defaultValue={this.state.highcourtname}
    onChangeItem={item => this.setState({
        highcourtname: item.value
    })}
/>