在此示例中,作者使用以下行:
var customerObjectStore =
db.transaction("customers", "readwrite").objectStore("customers");
我不明白为什么“客户”被使用了两次。我已经尝试重命名其中任何一个,以查看它可能在哪里产生影响并且示例中断,因此它们显然有必要保留相同的名称。
在此示例中,作者使用以下行:
var customerObjectStore =
db.transaction("customers", "readwrite").objectStore("customers");
我不明白为什么“客户”被使用了两次。我已经尝试重命名其中任何一个,以查看它可能在哪里产生影响并且示例中断,因此它们显然有必要保留相同的名称。
该transaction
方法有两个参数。第一个是您要使用的表(对象存储)数组,第二个是访问类型。在您的示例中,您只想使用一个表,因此您使用了字符串而不是数组。但是,如果您想处理大型项目,您应该使用多个表,如下所示:
var trans = db.transaction(["customers", "payments"], "readwrite");
var customerObjectStore = trans.objectStore("customers");
var paymentObjectStore = trans.objectStore("payments");
希望这个例子能解决你的困惑。