Cordova 未捕获类型错误:无法读取属性';价值';nullopenRequest.onupgradeRequired Indexeddb的
当我试图在IndexDB中打开两个对象并从输入值中获取数据时,遇到了上述情况。请告诉我哪里错了,下面是代码Cordova 未捕获类型错误:无法读取属性';价值';nullopenRequest.onupgradeRequired Indexeddb的,cordova,Cordova,当我试图在IndexDB中打开两个对象并从输入值中获取数据时,遇到了上述情况。请告诉我哪里错了,下面是代码 openRequest.onupgradeneeded = function(e) { var thisDB = e.target.result; var tab1Create = thisDB.createObjectStore("users", {keyPath: "phone"}); var tab2Create = thisDB.createO
openRequest.onupgradeneeded = function(e) {
var thisDB = e.target.result;
var tab1Create = thisDB.createObjectStore("users", {keyPath: "phone"});
var tab2Create = thisDB.createObjectStore("Friends", {keyPath: "frdphone"});
db = e.target.result;
var transaction = e.target.transaction;
var phone = document.querySelector("#phone").value;
var email = document.querySelector("#email").value;
var frdphone = document.querySelector("#frdphone").value;
var frdname = document.querySelector('#frdname').value;
var friend = transaction.objectStore('Friends');
friend.add({
frdname:frdname,
frdphone:frdphone
});
var user = transaction.objectStore('users');
//Perform the add
user.add({
phone :phone,
email :email
});
阅读错误消息: 未捕获的TypeError:无法读取null的属性“值” 对属性“value”(代码中的
something.value
)的一次访问失败,因为something
为空。使用.value
的地方只有document.querySelector()
调用。其中一个是不返回结果,即null
这与索引数据库无关-您使用的选择器与文档中的任何元素都不匹配。谢谢您,Joshua,修复了空值,我收到错误“Uncaught DataCloneError:未能对“IDBObjectStore”执行“add”:无法克隆对象。”请问有什么问题?没有更多的背景很难说。这表明(正如上面所说)无法克隆传递给
.add()
的对象。在给定的代码示例中,您似乎要传递包含字符串的对象,这应该没问题。猜测:您是否更改了var phone=document.querySelector(“#phone”).value
tovar phone=document.querySelector(“电话”)代码>?这意味着phone
正在引用一个元素,不能克隆元素。我建议您尝试执行console.log(…)
或尝试其他调试方法,以了解代码没有达到预期效果的原因。感谢您也尝试一下。