[英]How to update a record in react native
I am using firebase to store my data. 我正在使用Firebase存储我的数据。 When I am adding or getting data, there is no problem. 当我添加或获取数据时,没有问题。 But I can't update an existing report. 但是我无法更新现有报告。 For example, I have notes. 例如,我有笔记。 And user can open a note, edit and save. 用户可以打开笔记,进行编辑并保存。 On save, it should save the changes on existing record. 保存时,应将更改保存在现有记录中。 But I can't do that. 但是我做不到。
Here is how I tried. 这是我尝试过的方法。
fetch('https://shared-places-***.firebaseio.com/notes.json/' + this.state.updatedNote,{
method:'POST',
body: JSON.stringify({
Header: this.state.newNoteHeader,
Explanation: this.state.newNoteSub,
Date: new Date(),
})
})
.then(res => console.log(res))
.catch(err => console.log(err))
I have added my id to request link hoping I directly effect it but it didn't work. 我已经添加了我的ID来请求链接,希望我直接实现它,但是没有用。 Also tried changing method to Update but also didn't work of course. 还尝试将方法更改为Update,但当然也没有用。 I have searched but couldn't find an answer. 我已经搜索过,但是找不到答案。
Thank you in advance. 先感谢您。
I have found the answer that I was making small mistakes. 我找到的答案是我犯了一些小错误。 First of all, method should be PUT
not POST
. 首先,方法应该是PUT
而不是POST
。 Also address should be https://shared-places-***.firebaseio.com/notes/' + this.state.updatedNote + '.json'
地址也应为https://shared-places-***.firebaseio.com/notes/' + this.state.updatedNote + '.json'
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.