“Uncaught TypeError: Cannot use 'in' operator to search for 'length' in ” triggered by Datatables plugin and jQuery 1.11.3

后端 未结 8 1185
北恋
北恋 2021-02-12 13:17

I\'m using the jQuery Datatables plugin to enable pagination, sorting and searching with my tables. The elements are showing up but not working, and the pagination only sometime

8条回答
  •  忘掉有多难
    2021-02-12 13:33

    That error is because of the method isArraylike in jQuery version 1.11.3. (only). The method looks like this

    function isArraylike( obj ) {
    
        // Support: iOS 8.2 (not reproducible in simulator)
        // `in` check used to prevent JIT error (gh-2145)
        // hasOwn isn't used here due to false negatives
        // regarding Nodelist length in IE
        var length = "length" in obj && obj.length, // <------ THIS IS THE CULPRIT
            type = jQuery.type( obj );
    
        .......
    }
    

    That version of jQuery was using "length" in object to get the length. (I do not know anything about it).

    But I do know that no other versions of jquery have that issue.

    The versions 1.11.3 and 2.1.4 (as James pointed out in the comments) have this issue.

    So the solution would be to just upgrade to the next version or at least use any other version apart from 1.11.3 or 2.1.4

提交回复
热议问题