find CallBack fires more than once sometimes

84 Views Asked by At

Im fetching data from from Parse and try to show it. Problem im facing right now is find callback is firing multiple times sometimes. How can I stop this? Thanks.

var args = [];

query.find({
    success : function(results ) {

        args = {
            name : results[0].get('name'),
            address : results[0].get('address'),
            sex : results[0].get('sex'),
            email : results[0].get('email'),
            age : results[0].get('age')
        };
        var personView = Alloy.createController("personDetails", args).getView();
        if (OS_IOS) {
            $.navGroupWin.openWindow(personView);
        }
        if (OS_ANDROID) {
            personView.open();
        }   // args1 = JSON.parse(JSON.stringify(args));
        // Do something with the returned Parse.Object values
    },
1

There are 1 best solutions below

2
On BEST ANSWER

I experienced the same issue. Here is how I fixed it:

var succInvoked = false;

query.find({
    success : function(results ) {

        if (succInvoked) {
            return;
        }

        succInvoked = true;

        // your success callback here

    },