“未捕获类型错误:不能使用'在'操作符中搜索”长度“在”由Datatables插件和jQuery 1.11.3触发 [英] "Uncaught TypeError: Cannot use 'in' operator to search for 'length' in " triggered by Datatables plugin and jQuery 1.11.3

查看:279
本文介绍了“未捕获类型错误:不能使用'在'操作符中搜索”长度“在”由Datatables插件和jQuery 1.11.3触发的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用jQuery Datatables插件来启用分页,排序和搜索。元素显示但不起作用,分页仅有时会出现。在Chrome控制台中,我收到错误:

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 sometimes shows up. In Chrome console I'm getting the error:

Uncaught TypeError: Cannot use 'in' operator to search for 'length' in 

这是演示页面。

我在这个插件旁边使用Bootstrap。

I'm using Bootstrap alongside this plugin.

推荐答案

这个错误是因为jQuery版本1.11.3中的 isArraylike 方法。 (只要)。该方法看起来像这样

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 );

    .......
}

版本的jQuery在对象中使用length来获取长度。 (我不知道什么)

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

但是我知道没有其他版本的jquery有这个问题。

版本1.11.3和2.1.4(正如James在评论中指出的)有这个问题。

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

所以解决方案只是升级到下一个版本,或至少使用除1.11.3或2.1.4之外的任何其他版本。

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

这篇关于“未捕获类型错误:不能使用'在'操作符中搜索”长度“在”由Datatables插件和jQuery 1.11.3触发的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆