JavaScript for for循环和for-in循环,用于从数据库中获取数据

时间:2017-03-03 19:27:07

标签: javascript database for-loop

var fetchResults = tx.executeSql("SELECT * FROM sessions WHERE sessions.dayid=1 ORDER BY sessions.starttime ASC", [],
        function(tx, data){
            processorFunc(data);
            var contxt = "";
            for (var numb = 0; numb < data.rows.length; numb++) {
                contxt += data.rows[numb].title + "=" + data.rows[numb].startTime + "=" + 
                        data.rows[numb].endtime + "=" + data.rows[numb].type + "\n";
            }
            console.log(contxt);
            contxt = "";
            for (var numb in data.rows) {
                contxt += data.rows[numb].title + "=" + data.rows[numb].startTime + "=" + 
                        data.rows[numb].endtime + "=" + data.rows[numb].type + "\n";
            }
            console.log(contxt);
        });

在控制台中,我看到for-in循环返回两行,并且所有元素都是未定义的。我在这里使用Web Sql API。 enter image description here

有人知道为什么会这样吗?

0 个答案:

没有答案