我可以从 fire-base 添加和获取数据,但我不知道如何将键值传递给删除函数我已经上传了我的 firebase 数据存储结构。我需要从数据库中删除项目并呈现剩余的项目。var data = []export default class App extends React.Component { constructor(props) { super(props); this.state = { listViewData: data, newTodo: '', } } componentDidMount() { var that = this firebase.database().ref('/todos').on('child_added', function (snapshot) { var newData = [...that.state.listViewData] newData.push(snapshot) that.setState({ listViewData: newData }) }) } addRow() { if(this.state.newTodo == ''){ alert('Please enter Todo') } else { var d = new Date() var key = firebase.database().ref('/todos').push().key // firebase.database().ref('/todos').child(key).set({ id: key, //key title: this.state.newTodo , date: d.getDate()+ '/'+ (d.getMonth() + 1)+ '/'+ d.getFullYear() }) } } deleteRow() { firebase.database().ref('todos' + key).set(null) // rowMap[`${secId}${rowId}`].props.closeRow(); //var newData = [...this.state.listViewData]; // newData.splice(rowId, 1) //this.setState({ listViewData: newData }) } renderSeparator = () => { return ( <View style={{ height: 1, width: "100%", backgroundColor: "#CED0CE", }} /> ); };我在删除函数中尝试了 firebase.database().ref('todos' + key).set(null) 但没有得到像键值这样的错误。请检查我的删除函数,我做错了什么,请帮助我。
添加回答
举报
0/150
提交
取消
