test

博客园 首页 新随笔 联系 订阅 管理
class QuestionCheck extends Component {
  constructor(props) {
    super(props);
    this.state = {
      checked: props.checked
    };
    
  }
  changeSel = () => {
    this.props.setCheckd(this.props, !this.state.checked);
    this.setState({
      checked: !this.state.checked,
    });
  };

  componentWillReceiveProps(nextProps){
    if(this.props.checked !== nextProps.checked){
      this.setState({
        checked:nextProps.checked
      })
    }
  }

  render() {
    return (
      <View style={{ flexDirection: 'row', marginBottom: 10 }} >
        <CheckBox
          onPress={() => {
            this.changeSel();
          }}
          checked={this.state.checked}
          square={true}
          color="#DFDFDF"
        />
        <Text style={{ marginLeft: 20 }}>{this.props.name}</Text>
      </View>
    );
  }
}
  render() {
    const baseQuestion1Des = [
      { id: '1', name: 'aaa', checked: false },
      { id: '2', name: 'bbb', checked: false },
      { id: '3', name: 'ccc', checked: false }
    ];
<Item underline>
              <Text style={styles.textSize}>类型:</Text>
              <View style={{ padding: 10,  marginTop: 10 }}>
              <List
                dataArray={baseQuestion1Des}
                rowHasChanged={(r1, r2) => {
                  return r1.checked !== r2.checked;
                }}
                renderRow={data => {
                  return (
                    <QuestionCheck setCheckd={this.setCheckd} {...data} />
                  );
                }}
              />
            </View>
            </Item>
}

 

posted on 2019-08-08 09:57  testgogogo  阅读(311)  评论(0编辑  收藏  举报