我正在尝试在一个用于检查名称重复的函数中将includes()
替换为indexOf()
,因为IE不支持includes()
。该函数仅运行一次,这意味着该函数一旦运行一次,直到页面重新加载(页面使用ajax加载其内容)之后,它才会再次运行
我尝试仅用includes(false)
更改indexOf(false)
并传递类似indexOf(v,false)的参数,但是它不能正常工作。验证工作正常,但是当我关闭警报时,它将再次运行检查
session.page.nameCheck = true; //I set nameCheck as true to make the "run once" funcion
validateName: function() {
var trimSort = function(name) {
return $("[name=" + name + "]").map(function() {
return this.value.trim();
}).get().sort();
},
checkName = function(array, name) {
for (var i = 0; i < array.length; i++) {
if (array[i] == array[i + 1] && array[i] != "") {
showInfo(translator.getTranslation('There are duplicated names "' + array[i] + '" with different personal id´s. Check if that is correct, then continue.'));
$('input[name=' + name + '').each(function() {
if ($(this).val() !== '') {
$(this).addClass('invalid')
}
});
return false;
}
}
};
var valid = true;
valid = valid && !["RE_SignedByName", "RE_OwnersName"].map(function(v) {
checkName(trimSort(v), v);
}).includes(false); //this is the line that doesnt work on IE and I replaces it with indexOf() which almost work but not quite...
return valid;
},
我希望将includes(false)
的{{1}}替换为indexOf()
,以便它可以在IE上运行
FIX:
更新:因为我无法将其写为答案...解决方法是--
var valid = true;
valid = valid && !["RE_SignedByName", "RE_OwnersName"].map(function(v) {
checkName(trimSort(v), v);
}).indexOf(valid) !== -1;