How do I update data in indexedDB?

后端 未结 4 998
情书的邮戳
情书的邮戳 2021-02-07 20:48

I have tried to get some information from W3C regarding the update of an objectStore item in a indexedDB database, but with not so much susccess. I found here a way to do it, bu

4条回答
  •  没有蜡笔的小新
    2021-02-07 21:47

    A bit late for an answer, but possible it helps others. I still stumbled -as i guess- over the same problem, but it's very simple:

    If you want to INSERT or UPDATE records you use objectStore.put(object) (help)
    If you only want to INSERT records you use objectStore.add(object) (help)

    So if you use add(object), and a record key still exists in DB, it will not overwritten and fires error 0 "ConstraintError: Key already exists in the object store".

    If you use put(object), it will be overwritten.

提交回复
热议问题