我正在尝试在React Native中创建一个ListView,每一行都有一个复选框和正文。为此,我使用了NativeBase包。http://nativebase.io/docs/v2.0.0/components#checkbox
我遇到了一些问题,当我点击复选框时,复选框不会将状态更改为false。当我点击复选框时,如何获取正文的值?
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;