javascript - Type error: invalid 'in' operand e in jquery 1.10.2v - Stack Overflow

I have upgraded to jQuery 1.10.2 in my application, and I am getting an error in my code (in $.each). &

I have upgraded to jQuery 1.10.2 in my application, and I am getting an error in my code (in $.each).

'invalid 'in' operand e' .

This error occured after upgrading jQuery. In 'this._currentFilterbarValue', there is a string value which I need to check against some condition.

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

I have upgraded to jQuery 1.10.2 in my application, and I am getting an error in my code (in $.each).

'invalid 'in' operand e' .

This error occured after upgrading jQuery. In 'this._currentFilterbarValue', there is a string value which I need to check against some condition.

_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;
},
Share Improve this question edited Dec 11, 2013 at 6:58 Pranav 웃 8,4676 gold badges40 silver badges48 bronze badges asked Dec 11, 2013 at 6:32 RGRRGR 1,5712 gold badges23 silver badges37 bronze badges 1
  • what type of _currentFilterbarValue ? – Grundy Commented Dec 11, 2013 at 6:37
Add a ment  | 

1 Answer 1

Reset to default 4

What you are trying is to iterate through the characters in this._currentFilterbarValue(which is a string) and therefore jQuery.each() is failing

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

So try like

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

Another approach,

Converting your string this._currentFilterColumn to character array and then iterating using $.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;
});

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744789025a4593801.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信