Nativebase: how to get a selected Label name in Picker Component

Created on 20 Jan 2018  路  1Comment  路  Source: GeekyAnts/NativeBase

First of all, thank for your all components it's very good. I am using picker component. It's all working fine. My question is how to get a selected Label name. I am getting only selected index value. Please give me any suggestion. Thanks in advance
Here is my code:

import React, { Component } from 'react'
import { Platform } from 'react-native'
import { Container, Header, Title, Content, Button, Icon, Text, Right, Body, Left, Picker, Form, Item } from 'native-base'

var array = [
  {
    label: 'Wallet'
  },
  {
    label: 'ATM Card'
  },
  {
    label: 'Debit Card'
  },
  {
    label: 'Credit Card'
  },
  {
    label: 'Net Banking'
  }
]
export default class Courses extends Component {
  constructor(props) {
    super(props)
    this.state = {
      selected2: undefined,
      labelName: ''
    }
  }
  onValueChange2(value, label) {

    this.setState(
      {
        selected2: value,
        labelName: label
      },
      () => {
        console.log('selectedValue: ' + this.state.labelName)
      }
    )
  }
  render() {
    var description = []

    {
      array.map((res, i) => {
        description.push(<Item label={res.label} value={i} />)
      })
    }
    return (
      <Container>
        <Header>
          <Left>
            <Button transparent onPress={() => this.props.navigation.goBack()}>
              <Icon name="arrow-back" />
            </Button>
          </Left>
          <Body>
            <Title>Placeholder Picker w/o Note</Title>
          </Body>
          <Right />
        </Header>
        <Content>
          <Form>
            <Picker mode="dropdown" placeholder="Select One" note={false} selectedValue={this.state.selected2} onValueChange={this.onValueChange2.bind(this)}>
              {description}
            </Picker>
          </Form>
        </Content>
      </Container>
    )
  }
}



>All comments

Finally, I got an answer.

{
      array.map((res, i) => {
        description.push(<Item label={res.label} value={res.label} />)
      })
    }
Was this page helpful?
0 / 5 - 0 ratings

Related issues

maphongba008 picture maphongba008  路  3Comments

eggybot picture eggybot  路  3Comments

bsiddiqui picture bsiddiqui  路  3Comments

natashache picture natashache  路  3Comments

agersoncgps picture agersoncgps  路  3Comments