jQuery $.each 问题与 iOS Safari 上的 for 循环
jQuery $.each issue vs for loop on 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;
},
我这周遇到了同样的问题。我在 jQuery bugtracker 中发现了以下错误报告:
https://github.com/jquery/jquery/issues/2145
WebKit 错误:
https://bugs.webkit.org/show_bug.cgi?id=142792
正在修复中:-)
我在 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;
},
我这周遇到了同样的问题。我在 jQuery bugtracker 中发现了以下错误报告: https://github.com/jquery/jquery/issues/2145
WebKit 错误: https://bugs.webkit.org/show_bug.cgi?id=142792
正在修复中:-)