Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/81.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 如何使用嵌套游标从IndexedDB读取数据?_Javascript_Html_Ecmascript 6_Indexeddb - Fatal编程技术网

Javascript 如何使用嵌套游标从IndexedDB读取数据?

Javascript 如何使用嵌套游标从IndexedDB读取数据?,javascript,html,ecmascript-6,indexeddb,Javascript,Html,Ecmascript 6,Indexeddb,我正在尝试从IndexedDB中的两个不同对象存储读取数据。我正在使用“嵌套”游标。但它不起作用,我例外。当我单独阅读时,它会起作用 对于第一个学生,它通过内部光标一次,对于第二个学生两次,依此类推 我必须将IndexedDB与ECMAScript 6一起使用 这是我的密码: function listMarkByStudents(event){ let transaction = db.transaction(["students", "marks"], "readonly");

我正在尝试从IndexedDB中的两个不同对象存储读取数据。我正在使用“嵌套”游标。但它不起作用,我例外。当我单独阅读时,它会起作用

对于第一个学生,它通过内部光标一次,对于第二个学生两次,依此类推

我必须将IndexedDB与ECMAScript 6一起使用

这是我的密码:

function listMarkByStudents(event){

    let transaction = db.transaction(["students", "marks"], "readonly");
    let storeStudents = transaction.objectStore("students");
    let storeMarks = transaction.objectStore("marks");

    let indexStudents = storeStudents.index('sName');
    let indexMarks = storeMarks.index('idStudent')

    let output = '';

    indexStudents.openCursor().onsuccess = function (event){
        let cursorStudents = event.target.result;
        if(cursorStudents){
            output += "<tr>";
            output += "<td>"+cursorStudents.value.id+"</td>";
            output += "<td>"+cursorStudents.value.sName+"</td>";
            output += "<td>"+cursorStudents.value.email+"</td>";
            output += "</tr>";

            indexMarks.openCursor().onsuccess = function (event){
                let cursorMarks = event.target.result;
                if (cursorMarks){
                    output += "<tr>";
                    output += "<td>"+cursorMarks.value.markValue+"</td>";
                    output += "<td>"+cursorMarks.value.idStudent+"</td>";
                    output += "<td>"+cursorMarks.value.idSubject+"</td>";
                    output += "</tr>";

                    cursorMarks.continue();
                }
            }
            cursorStudents.continue();
        }       
        document.getElementById('StudentsMarkList').innerHTML = output;
    }
}
函数列表MarkByStudents(事件){
let transaction=db.transaction([“学生”,“分数”],“只读”);
让storeStudents=transaction.objectStore(“students”);
让storeMarks=transaction.objectStore(“marks”);
让indexStudents=storeStudents.index('sName');
让indexMarks=storeMarks.index('idStudent')
让输出=“”;
indexStudents.openCursor().onsuccess=函数(事件){
让cursorStudents=event.target.result;
如果(游标学生){
输出+=“”;
输出+=“”+cursorStudents.value.id+“”;
输出+=“”+cursorStudents.value.sName+“”;
输出+=“”+cursorStudents.value.email+“”;
输出+=“”;
indexMarks.openCursor().onsuccess=函数(事件){
让cursorMarks=event.target.result;
if(光标标记){
输出+=“”;
输出+=“”+cursorMarks.value.markValue+“”;
输出+=“”+cursorMarks.value.idStudent+“”;
输出+=“”+cursorMarks.value.idSubject+“”;
输出+=“”;
cursorMarks.continue();
}
}
cursorStudents.continue();
}       
document.getElementById('StudentsMarkList')。innerHTML=output;
}
}

与解决问题无关,但现代JS提出的一个重要问题是:为什么要使用字符串连接而不是使用
document.createElement
element.appendChild
等构建普通DOM节点?此代码不起作用,您需要重新执行查询以获得嵌套游标和嵌套游标,但是我完全放弃这种方法,只在没有嵌套的情况下使用两个游标