vendredi 24 mars 2017

React Native List View

I am trying to create a Listview in react native, each row have a checkbox and a body text. To do this I am using nativebase package. http://ift.tt/2ngeqNQ

I have some problems, when I click in the checkBox the checkbox doesn't change the state to false. How can I get the value from the body text when I click in the checkbox ?

import React, { Component } from 'react';
import { Container, Content, List, Body, ListItem, Text, CheckBox } from 'native-base';

class ListExample extends Component {
  state = {
    pressed: true,
    value: ""
  };

  onCheckBoxPress() {
    console.log(this);
    this.setState({ pressed: false});
    this.setState({ value: BODYVALUE});
  }

  render() {
    var items = [ "test1", "test2", "test3", "test4", "test5", "test6" ];
    return (
      <Container>
      <Content>
          <List dataArray={items} renderRow={(data) =>
              <ListItem>
                <CheckBox onPress={this.onCheckBoxPress.bind(this)} checked={this.state.pressed} />
                <Body>
                  <Text>{data}</Text>
                </Body>
              </ListItem>
          } />
      </Content>
  </Container>
    );
  }
}

export default ListExample;




Aucun commentaire:

Enregistrer un commentaire