0
  var processResult = function(items)
{

    return  items;
};
    function queryDB(callback) {

            var sqlTxt = "SELECT * FROM DEMO";
            db.transaction(
                    function(tx) {
                        tx.executeSql(sqlTxt, [],
                                function(tx, results) {
                                    var item_Codes = [];
                                    for (var i = 0; i < results.rows.length; i++) {

                                        item_Codes.push({item_code: results.rows.item(i).itemCode});
                                    }
                                    callback(item_Codes);
                                })
                                , errorCB;
                    });
            return false;
        }

Main.js

  queryDB(processResult, function(arr) {
            $.each(arr, function(i, elem) {

        });
    });

In above Code item_Codes is array.Here i need to print the Array after the data is loaded.But when i try to print the array it displays null. How Can i print the Array after the data is loaded to the Array.

1
  • Can you eloborate your answer Commented Nov 14, 2013 at 5:04

2 Answers 2

1

You don't use the variable after the call, you use the parameter in the callback function that you send in the call:

queryDB(function(arr){
  console.log(arr);
});
Sign up to request clarification or add additional context in comments.

3 Comments

@user2889058: If you change your question to look like the answer, other people won't understand the answer.
Hwy sorry for the mistake.But when i try i still gives me error.11-14 11:23:28.718: E/Web Console(8418): Uncaught TypeError: undefined is not a function:67
@user2889058: Now you have two callback functions in the call, but the function only uses the first. It seems that the variable processResult doesn't exist where you use it, did you create it inside a function scope?
0

why not you try :

function queryDB(callback) {



   var sqlTxt = "SELECT * FROM DEMO";
    db.transaction(
            function(tx) {
                tx.executeSql(sqlTxt, [],
                        function(tx, results) {
                            var item_Codes = [];
                            for (var i = 0; i < results.rows.length; i++) {

                                item_Codes.push({item_code: results.rows.item(i).itemCode});
                            }
                            callback(item_Codes);
                        })
                        , errorCB;
            });
    console.log(item_codes);
    return false;
}

That is, I am just trying to print out the value of your array after the code executes.

1 Comment

Actually i need to print the array from another file.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.