External variable gets value from an Success

Asked

Viewed 30 times

1

I am unable to recover the value of the variable countEventChecks after Success. How can I assign the value of a return to another variable?

for (var x = 0; x < eventosCkeckedPeloUser.length; x++) {
    if (eventosResponse[i].id == eventosCkeckedPeloUser[x].id) {
        confirmCheck = true;
        evento = {
            "id": eventosResponse[i].id,
            "img": eventosResponse[i].get("eve_imagem"),
            "checks": countChecks(eventosResponse[i]),
            "userCheck": confirmCheck
        }
        $scope.eventos.push(evento);
    } 
}

function countChecks(evento) {
    var relation = evento.relation("eve_users");
    var query = relation.query();
    query.count({
        success: function (res) {
            return res;
        }
    });
}

1 answer

1

EDIT

function countChecks(evento, data) {
    var relation = evento.relation("eve_users");
    var query = relation.query();
    function data(response) {
        query.count({
            success: function (res) {
                data(res); 
            }
        });
    }
}

for (var x = 0; x < eventosCkeckedPeloUser.length; x++) {
    if (eventosResponse[i].id == eventosCkeckedPeloUser[x].id) {
        confirmCheck = true;
        evento = {
            "id": eventosResponse[i].id,
            "img": eventosResponse[i].get("eve_imagem"),
            "checks": countChecks(eventosResponse[i], function(res) {
                        return res;
                    }),
            "userCheck": confirmCheck
        }
        $scope.eventos.push(evento);
    } 
}
  • I’ve tried it this way but it’s returning Undefined. When I put console.log(res) inside Success it prints the correct value. But when I invoke the Function countChecks(event) out the return is Undefined.

  • You need a synchronous call, I edited the script, make sure it works.

  • I think I still don’t understand. I edited the code to see where to call the function.

  • I reissued the code complementing with your edition, check that I will explain what I did depending on the result

  • Well, it keeps printing Undefined. But I think it’s something of Parse’s. I must be making a wrong call. I’ll study Parse some more. Thank you.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.