简体   繁体   中英

How do I work with query results - Javascript (Azure Database)

so I am using Microsoft Visual Studio 2013 with Apache Cordova at the moment and using Microsoft Azure as the backend database (New to this!). I have written the following code as a test and I can't seem to work with the results of a query. alert(JSON.stringify(results)) seems to work and is alerting the query results as [{"id":"1234","username":"james","password":"james"}]. However, when I try to use results.length or results.'anything', it is not recognising results as an array. Is there a way I can work with the query results? Help is much appreciated :)

 function test() {

    //Query the Accounts table where the input fields match a record in the table.

    var query = accountsTable.where({
        username: textUsername.value,
        password: textPassword.value
    }).read().done(function (results) {
        alert(JSON.stringify(results));
        var queryTest = results[0].text;
    }, function (err) {
        alert("Error: " + err);
    });
}

这是我输入“结果”时得到的结果。

You need to specify property name, it seems you are specifying the text , which is not there.

For single record:

var query = accountsTable.where({
    username: textUsername.value,
    password: textPassword.value
}).read().done(function (results) {
    alert(results[0].id + " " + results[0].username + " " + results[0].password);
}, function (err) {
    alert("Error: " + err);
});

For multiple records:

var query = accountsTable.where({
    username: textUsername.value,
    password: textPassword.value
}).read().done(function (results) {
    for (var i = 0; i < results.length; i++) {
        alert(results[i].id + " " + results[i].username + " " + results[i].password);
    }
}, function (err) {
    alert("Error: " + err);
});

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM