External variable receives value from a success

1

I am not able to retrieve the value of the countEventChecks variable 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;
        }
    });
}
    
asked by anonymous 04.06.2016 / 14:38

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);
    } 
}
    
04.06.2016 / 14:48