Dmitry Sadakov
Dmitry Sadakov

Reputation: 2158

jQuery $.each issue vs for loop on iOS Safari

I'm having a strange issue on iOS Safari (yet not in chrome/ff/safari desktop). The $.each jquery method gets skipped (debugger doesn't step into the function), resulting in wrong computations. This is happening intermittedly, only 50% of the time:

     getActorStatesInternal = function(actor){
            var lampIds = hue.getLampIds(actors);
            var state = window.hue.getState();
            var actorStates= [];
            var actorStatesjQuery= [];
            if (state.lights !== null) {
                for(var i in state.lights) {
                    var lamp = state.lights[i];
                    lamp.key = i;
                    actorStates.push(lamp);
                }
                // each fails sometimes on ios safari
                $.each(state.lights, function(key, lamp) {
                    if (lampIds.indexOf(key) !== -1) {
                        lamp.key = key;
                        actorStatesjQuery.push(lamp);
                    }
                });
                log('ios safari actor count - js ' + 
                     actorStates.length + ' jq:' + actorStatesjQuery.length);
                // console.log: "ios safari actor count - js 3 jq: 0"

            } 
            return actorStates;
        },

Upvotes: 1

Views: 1296

Answers (1)

bjornoss
bjornoss

Reputation: 26

I had the same problem this week. I found the following bug report at the jQuery bugtracker: https://github.com/jquery/jquery/issues/2145

WebKit bug: https://bugs.webkit.org/show_bug.cgi?id=142792

A fix is on it's way :-)

Upvotes: 1

Related Questions