数日前、私は同じ問題で立ち往生しました。しかし今、このコードは私のために働いています
あなたのリストビューコード
<ListView
style={styles.container}
dataSource={this.state.dataSource}
renderRow={(data) =>
<View style={{ flex: 1, flexDirection: "column" }}>
<View style={{ flex: 1, flexDirection: "column" }}>
<View style={{ flex: 1, flexDirection: "row", alignItems: "center", justifyContent: "center", marginBottom: 0 }}>
<Text style={{ fontSize: 16, color: "#fff", padding: 5, textAlign: "center", width: 220, paddingLeft: 40, paddingRight: 40, borderStyle: "solid", borderRadius: 100, borderColor: "#fff", borderWidth: 1 }}>
{data.name}
</Text>
</View>
<TouchableHighlight
onPress={() => this.updateIndex(data._id)}>
<View style={{ alignItems: "center", justifyContent: "center", marginBottom: 5 }}>
{this.state.categoryIndex == data._id &&
<Text style={{ color: "#fff" }}>
<IonicIcons name="ios-arrow-up" style={{ fontSize: 20, marginTop: 10, padding: 0 }} />
<Text> Less</Text>
</Text>
}
{this.state.categoryIndex != data._id &&
<Text style={{ color: "#fff" }}>
<IonicIcons name="ios-arrow-down" style={{ fontSize: 20, marginTop: 10, padding: 0 }} />
<Text> More</Text>
</Text>
}
</View>
</TouchableHighlight>
</View>
{this._renderCancel(data)}
</View>
}
updateIndex() 関数を呼び出す必要があります。この関数は、子ビューを開く必要がある状態IDを更新するだけです
this.state.categoryIndex == data._id は ListView を開き、 this.state.categoryIndex != data._id の場合は子 ListView を閉じます
私の updateIndex() 関数は次のようになります
updateIndex(index) {
if (this.state.showSubcategory && this.state.categoryIndex == index) {
this.setState({
showSubcategory: !this.state.showSubcategory,
categoryIndex: false
});
} else {
this.setState({
showSubcategory: true,
categoryIndex: index
});
}
}