我该如何在react-native列表中创建一个相同的孩子?

时间:2018-07-22 10:06:07

标签: list react-native

我有一个列表,有一个文本和一个计数器。我得到this['counter${secId}${rowId}'].getCounterValue()的对价,但遇到了一些问题。当我删除任何行时,计数器会在该行下降。 counter${secId}${rowId}不同。我该如何解决?

Before Screen

After Screen and I didn't change work's counter

<List
            leftOpenValue={75}
            rightOpenValue={-75}
            enableEmptySections={true}
            dataSource={this.state.sentenceDS}
            renderRow={(data, secId, rowId) =>
              <ListItem
                style={styles.lstItm}>
                <Text> {data} </Text>

                <Counter
                  onRef={ref => (this[`counter${secId}${rowId}`] = ref)}
                />

              </ListItem>}
            renderLeftHiddenRow={data =>
              <Button full onPress={() => alert(data)}>
                <Icon active name="information-circle" />
              </Button>}
            renderRightHiddenRow={(data, secId, rowId, rowMap) =>
              <Button full danger onPress={_ => this.deleteRow(secId, rowId, rowMap)}>
                <Icon active name="trash" />
              </Button>}
          />

deleteRow(secId, rowId, rowMap) {
    //this.closeRow(secId, rowId);
    rowMap[`${secId}${rowId}`].props.closeRow();
    const newData = [...this.sentences];
    newData.splice(rowId, 1);
    this.sentences = newData;
    this.setState({ sentenceDS: this.state.sentenceDS.cloneWithRows(this.sentences) });



    alert(this[`counter${secId}${rowId}`].getCounterValue())


  }

0 个答案:

没有答案