如何在 React Native 中更新记录

How to update a record in react native

我正在使用 firebase 来存储我的数据。当我添加或获取数据时,没有问题。但我无法更新现有报告。例如,我有笔记。用户可以打开笔记、编辑和保存。保存时,它应该保存对现有记录的更改。但是我做不到。

这是我尝试过的方法。

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))

我已经添加了我的 id 来请求 link 希望我能直接影响它,但它没有用。还尝试将方法更改为 Update 但当然也没有用。我已搜索但找不到答案。

提前致谢。

我找到了我犯了小错误的答案。首先,方法应该是 PUT 而不是 POST。地址也应该是 https://shared-places-***.firebaseio.com/notes/' + this.state.updatedNote + '.json'