我有一阵.,含有约6300个元素。
我试图通过这些内容利用 j子,并为一些可以用来过滤6300个元素的下级清单制定备选办法清单。
在欧安办事处,这项工作没有问题,但在伊埃,我对手稿有误。 我在玩弄该法典,试图获得一套数据,而不造成IEE的错误,但迄今为止,我没有幸运。 以下是我已经尝试的方法:
利用“指标”编制一个单独的“管辖权清单”。
var arrayJurisdiction = dataSet.filter(function (item, i, a) {
return i.Jurisdiction == a.indexOf(item.Jurisdiction);
});
核对每个要素,检查是否在二级阵列中已经存在价值,如果是没有,则添加。
g$.each(dataSet, function (key, value) {
var matchingJurisdiction = arrayJurisdiction.filter(function (item) {
return value.Jurisdiction == item;
})[0];
if (matchingJurisdiction == null) {
arrayJurisdiction.push(value.Jurisdiction);
}
});
Both of these methods result in IE giving me an error about a script running too slowly. Is there any faster way of doing this?
*EDIT*** Based on feedback below, I have changed the method to use for loops instead of .each() and .filter(), but I am still receiving the "stop this script?" dialog in IE.
这里是使用假体的经修订的法典。 此外,我还包括了我试图填满的所有过滤器(而不仅仅是第一个过滤器)。
for (var i = 0; i < dataSet.length; i++) {
var value = dataSet[i];
var matchingJurisdiction = null;
for (var i = 0; i < arrayJurisdiction.length; i++) {
var item = arrayJurisdiction[i];
if (item == value.Jurisdiction) {
matchingJurisdiction == item;
break;
}
}
if (matchingJurisdiction == null) {
arrayJurisdiction.push(value.Jurisdiction);
}
var valueYear = new Date(value.Treatment_Date).getFullYear();
var matchingYear = null;
for (var i = 0; i < arrayYear.length; i++) {
var item = arrayYear[i];
if (item == valueYear) {
matchingYear == item;
break;
}
}
if (matchingYear == null) {
arrayYear.push(valueYear);
}
var matchingProjectClass = null;
for (var i = 0; i < arrayProjectClass.length; i++) {
var item = arrayProjectClass[i];
if (item == valueYear) {
matchingProjectClass == item;
break;
}
}
if (matchingProjectClass == null) {
arrayProjectClass.push(value.Project_Classification);
}
var matchingImprovementType = null;
for (var i = 0; i < arrayImprovementType.length; i++) {
var item = arrayImprovementType[i];
if (item == valueYear) {
matchingImprovementType == item;
break;
}
}
if (matchingImprovementType == null) {
arrayImprovementType.push(value.Improvement_Type);
}
}