You must execute the res.view AFTER retrieving the data in the callback. My
first guess in your case:

index : function(req, res){
        graph.setAccessToken(req.user.token);
        var events = [];
        graph.get("/me/events?limit=500", {limit: 500},  function(err, rep)
{
            for(key in rep["data"]){
                var query = "SELECT eid, name, creator, description, pic,
pic_big, pic_cover, start_time, end_time FROM event WHERE eid=" +
rep["data"][key].id;
                graph.fql(query, function(err, event_hash) {
                    var ev = event_hash["data"][0];
                    if (ev.creator.toString() == req.user.uid.toString()) {
                        events.push(ev);
                    };

                    res.view({
                        events: events
                    });

                })
            };
        });


    },


On Mon, May 5, 2014 at 7:47 PM, Folivi Fofo <[email protected]> wrote:

> hi all,
>
> I'm working on an app where I need to display user's facebook events.
>
> The code below shows how to retrieve the users events and then perform a
> query to facebook api to retrieve more event details.
>
> As you can see, the process is: retrieving the events, then get more
> details about each, push all into an array then pass the array to the view.
>
> I fail in sending the array to the view and I believe it might have
> something to do with the asynchronous way of nodejs. Is this where the
> callback is needed?
>
> How can I solve this?
>
> Hope I'm clear.
>
> Thanks for your help
>
> index : function(req, res){
>         graph.setAccessToken(req.user.token);
>         var events = [];
>         graph.get("/me/events?limit=500", {limit: 500},  function(err,
> rep) {
>             for(key in rep["data"]){
>                 var query = "SELECT eid, name, creator, description, pic,
> pic_big, pic_cover, start_time, end_time FROM event WHERE eid=" +
> rep["data"][key].id;
>                 graph.fql(query, function(err, event_hash) {
>                     var ev = event_hash["data"][0];
>                     if (ev.creator.toString() == req.user.uid.toString()) {
>                         events.push(ev);
>                     };
>                 })
>             };
>         });
>         res.view({
>             events: events
>         });
>
>     },
>
>  --
> Job board: http://jobs.nodejs.org/
> New group rules:
> https://gist.github.com/othiym23/9886289#file-moderation-policy-md
> Old group rules:
> https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
> ---
> You received this message because you are subscribed to the Google Groups
> "nodejs" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to [email protected].
> To post to this group, send email to [email protected].
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/nodejs/b1f3b685-f439-4a19-9923-4d73416f6c03%40googlegroups.com<https://groups.google.com/d/msgid/nodejs/b1f3b685-f439-4a19-9923-4d73416f6c03%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
> For more options, visit https://groups.google.com/d/optout.
>

-- 
Job board: http://jobs.nodejs.org/
New group rules: 
https://gist.github.com/othiym23/9886289#file-moderation-policy-md
Old group rules: 
https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
--- 
You received this message because you are subscribed to the Google Groups 
"nodejs" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/nodejs/CAMs%2BDq%2BtgQj963BTNNBWNqBWbdUNxL5%2BKtkjTkSnGTWBM6YJAw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to