1

I have this function to get some data from the internet:

function GetData(callback) {
    var data = [
        ["username", "password", "email"]//Header values
    ];

    doc.getInfo(function (err, sheet_info) {  //the doc is an google spreadsheet object
         sheet_info.worksheets[0].getRows(function(err, rows) {
              _.forEach(rows, function(row) {
                data.push([row.name, row.password, row.email]);
     } );
    });

});



    callback(data);
}

But when i try to use this function:

GetData(function (data) {
    console.log(data) //Has only first initial values  ["username", "password", "email"]
});

Any idea what might be the problem ?

giannisf
  • 2,479
  • 1
  • 17
  • 29
  • yes i am working with http://handsontable.com/ – giannisf Sep 25 '14 at 13:46
  • 1
    `getRows` is asynchronous, and you do a `console.log(rows)` which only get later filled? Show us the code of `getRows`! – Bergi Sep 25 '14 at 13:47
  • 1
    You need to put the `callback(data);` right after the `_.forEach()` function inside the function passed to `getRows()`. – idbehold Sep 25 '14 at 16:56

0 Answers0