javascript - 类型错误 : invalid 'in' operand e in jquery 1. 10.2v

标签 javascript jquery

我已经在我的应用程序中升级到 jQuery 1.10.2,但我的代码中出现错误(在 $.each 中)。

'invalid 'in' operand e' .

这个错误发生在升级 jQuery 之后。在“this._currentFilterbarValue”中,有一个字符串值,我需要根据某些条件对其进行检查。

_CheckForSkipInput: function () {
    var IsSkip = false;
    if (this._currentFilterColumn.type == "String") {
        var stringSkipInput = new Array(">", "<", "=", "!");
        $.each(this._currentFilterbarValue, function (index, value) {
            if (jQuery.inArray(value, stringSkipInput) != -1)
                IsSkip = true;
        });
    }
    return IsSkip;
},

最佳答案

您尝试的是遍历 this._currentFilterbarValue(这是一个字符串)中的字符,因此 jQuery.each() 失败

The $.each() function can be used to iterate over any collection, whether it is an object or an array.

所以试试吧

 var IsSkip = false;
 if (this._currentFilterColumn.type == "String") {
     var stringSkipInput = new Array(">", "<", "=", "!");
     for (var i = 0; i < s.length; i++) {
         if (jQuery.inArray(s[i], stringSkipInput) != -1) IsSkip = true;
     }
 }
 return IsSkip;
 },

另一种方法,

将字符串 this._currentFilterColumn 转换为 字符数组,然后使用 $.each()

var arr = this._currentFilterColumn.split("");  //Converting a string to char array
$.each(arr, function (index, value) {  //Now iterate the character array
  if (jQuery.inArray(value, stringSkipInput) != -1) IsSkip = true;
});

关于javascript - 类型错误 : invalid 'in' operand e in jquery 1. 10.2v,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20512133/

相关文章:

javascript - Flash - 将音频数据 ByteArray 传递给 javascript

javascript - Vue.js 如何按每个组对数据进行切片并在顶部显示 3 行,然后显示其他行?

javascript - 3 行布局,100% 高度 : 1 auto, 1 自动滚动,1 固定

javascript - 如何查找 javascript 中失败或导致 javascript 崩溃/无法继续执行的行

javascript - jquery 中的 Click 事件是永久的吗

javascript - KnockoutJS 现在 jQuery 模板即将过时

javascript - 这个数组排序功能实际上是如何工作的?

javascript - 使用索引元素 ID 时出现意外错误

javascript - 开发 JavaScript 以进行缩小

jQuery 从序列化数组中删除项目