iOS Safari上的jQuery $ .each问题vs for循环

时间:2015-01-31 15:29:20

标签: javascript jquery ios safari

我在iOS Safari上遇到一个奇怪的问题(但不是在chrome / ff / safari桌面上)。 跳过$ .each jquery方法(调试器不会进入函数),导致计算错误。间歇性地发生这种情况,只占50%的时间:

     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;
        },

1 个答案:

答案 0 :(得分:1)

本周我遇到了同样的问题。我在jQuery bugtracker中发现了以下错误报告: https://github.com/jquery/jquery/issues/2145

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

正在修复它: - )