add和put in indexeddb有什么区别? [英] What is the difference between add and put in indexeddb?

查看:363
本文介绍了add和put in indexeddb有什么区别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚刚开始使用indexeddb并转换Web SQL.

I am just starting to use indexeddb and transforming Web SQL.

我试图使用add和put在数据存储中添加一些数据.我真的看不到使用这两个功能有什么区别.

I tried to use add and put to add some data in data store. I could not really see what is/are the difference/s of using these two functions.

我认为我必须知道它们之间的区别,以便可以适当地使用它们.

I think I have to know the difference so I could use them appropriately.

谢谢

推荐答案

add和put之间的区别与任何API相同.

The difference between add and put is same as in any API.

如果尝试使用put函数插入具有已存在键的元素,则它将触发并更新现有元素,但是,如果您使用add函数且具有相同id的元素存在,则会得到一个错误并显示以下消息:对象存储库中已存在密钥."

If you try to insert an element with key that already exist using the put function it will trigger and update of the existing element, however if you use the add function and element with same id exist you will get an error with the following message: "Key already exists in the object store."

这篇关于add和put in indexeddb有什么区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆