在删除给定用户时,我正在努力更新列表。大多数问题来自以下事实:我丢失了state
,因为我将函数作为componentDidMount
放在了setParams
中。
componentDidMount() {
...
this.props.navigation.setParams({ removeUser: this._deleteUser});
...
}
这是_deleteUsers
的功能,它可以删除但不能更新:
_deleteUser(){
var user = firebase.auth().currentUser;
var position;
_.map(this.selectedMembers, item => {
var ref = firebase.database().ref('path')
ref.orderByChild('key').equalTo(item.key).on("value", function(snapshot){
snapshot.forEach(function(child) {
position = child.key
});
});
delete this.students.members[position]
});
firebase.database().ref().child('path').remove();
Toast.show({
text: "Members deleted successfully!",
type: "success",
fontStyle: "italic",
})
}
所有这些都应在以下Flatlist
render() {
...
<FlatList
style={{
flex: 1,
width: "100%",
}}
refreshControl={
<RefreshControl
refreshing={this.state.refreshing}
onRefresh={this.refreshList}
/>}
data={this.state.dataSource}
ItemSeparatorComponent={this.FlatListItemSeparator}
renderItem = {this._renderItem}
listKey={item => item.uid}
extraData={this.state}
/>
}
,应用程序的状态为:
constructor(props) {
super(props)
this.state = {
dataSource : [],
text : '',
itemNumber : 0,
selectedItems: [],
groupName: '',
selectedMembers: [],
}
}
state = {
refreshing: false,
}
refreshList = () => {
this.state.refreshing = true;
this.props.navigation.state.params.store = new StudentsStore();
this.state.refreshing = false;
}
我应该如何处理?我还有许多其他操作,但是唯一不起作用的操作是该操作,因为我在componentDidMount
中进行操作的方式至少是这样,我认为这是我不知道如何解决的问题解决。
谢谢
答案 0 :(得分:1)
传递回调时,您将丢失上下文。用箭头函数包装回调,您将保留原始上下文。
更改:
let imageViewPoint = scrollView.convert(CGPoint(x: 50, y: 50), to: imageView)
为此:
componentDidMount() {
...
this.props.navigation.setParams({ removeUser: this._deleteUser});
...
}