javascript中的括号和括号

时间:2017-06-22 01:57:58

标签: javascript sqlite cordova

我正在尝试使用我的应用程序的cordova s​​qlite来从sqlite表中检索数据。我有以下代码来选择所有客户信息:

    db.executeSql("SELECT * FROM customerinformation WHERE lastName LIKE ? AND firstName LIKE ? ", [ lastName, firstName ], function(rs) {
        if (rs.rows.length > 0) {
            var response = {};
            if (rs.rows.item) {
                response.data = rs.rows.item;
            } else {
                response.data = [{}];
            }
            successCallback(response);
        } else {
            alert('No Record Found');
        }
    }, function(error) {
        alert(error.message);
    });

现在,如果我访问response.data [0],我会得到未定义的。但是,如果我尝试response.data(0),我可以看到客户信息的对象。如何将rs.rows.item传输到response.data数组?

1 个答案:

答案 0 :(得分:0)

我设法通过以下更改来完成此工作:

    db.executeSql("SELECT * FROM customerinformation WHERE lastName LIKE ? AND firstName LIKE ? ", [ lastName, firstName ], function(rs) {
        if (rs.rows.length > 0) {
            var response = {};
            response.data = [{}];
            if (rs.rows.item) {
                for (i=0;i<rs.rows.length; i++) {
                response.data[i] = rs.rows.item(i);
                }
            }
            successCallback(response);
        } else {
            alert('No Record Found');
        }
    }, function(error) {
        alert(error.message);
    });