jQuery “e.handler.apply”不是jquery表排序器中的函数

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/24283006/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-27 02:30:18  来源:igfitidea点击:

"e.handler.apply" is not a function in jquery table sorter

jquerytablesorter

提问by user3742125

In one of my application I am using JQUERY tablesorter.But while sorting with any of the cloumns I am getting below error. Any idea why this is happening.

在我的一个应用程序中,我使用的是 JQUERY tablesorter。但是在使用任何 cloumns 进行排序时,我遇到了以下错误。知道为什么会这样。

Error : "e.handler.apply" is not function in Jquery.js

错误:“e.handler.apply”在 Jquery.js 中不起作用

My code to use table sorter is as below.

我使用表格排序器的代码如下。

$(".tablesorter")
.tablesorter(
    {
        headers: { 0: { sorter: false}},
        widgets: ['zebra'],
        fixedHeight: false
    })
.tablesorterPager({
  container: $(".pager")
    });

$("#sortHeader").click(

    $(".tablesorter")
    .bind("sortStart",function(e, table) 
        {
            $('.tablesorter').trigger('pageSet',0);

        })

);

But If I am commenting the code which starts from "$("#sortHeader").click" then it is working fine. But I need that portion of code to meet my requirement.

但是,如果我正在评论从 "$("#sortHeader").click" 开始的代码,那么它工作正常。但是我需要那部分代码来满足我的要求。

Any thoughts on this.

关于这个的任何想法。

回答by Jai

You are missing a function()callback block of click:

您缺少以下function()回调块click

$("#sortHeader").click(function(){ // <-----you need to have a callback function.
    $(".tablesorter").bind("sortStart",function(e, table){
        $('.tablesorter').trigger('pageSet',0);
    });
}); // <---do a proper closing.


Issue in your code:

您的代码中的问题:

When you do :

当你这样做时:

$("#sortHeader").click(

without a callback function that will always gives you error in the jQuery library as you got to know Error : "e.handler.apply" is not function in Jquery.js

没有回调函数,它总是会在 jQuery 库中给你错误,因为你知道 Error : "e.handler.apply" is not function in Jquery.js

Because the way .click()method is written it needs a callback function to do something whenever you fire this event. so in your code jQuery thinks that whatever written in the (...here...)is a callback to the fired clickevent and it fails to apply that callback.

因为.click()编写方法的方式需要一个回调函数来在您触发此事件时执行某些操作。因此,在您的代码中,jQuery 认为 中编写的任何内容都是对(...here...)已触发click事件的回调,并且无法应用该回调。

回答by MarioDS

As it stands, what you're trying to do is to pass a parameter to jQuery's clickfunction. More specifically, the return value of your call to bind, which just returns a jQuery object, which is nota function, hence applyis undefined on it and this results in the error that you're getting.

就目前而言,您要做的是将参数传递给 jQuery 的click函数。更具体地说,您调用 的返回值,它只bind返回一个 jQuery 对象,它不是一个函数,因此apply在它上面是未定义的,这会导致您得到错误。

You need to wrap what you wrote inside click()in a function declaration:

您需要将您写在里面的内容包装click()在函数声明中:

$("#sortHeader").click( function(e) { //important!

$(".tablesorter")
.bind("sortStart",function(e, table) 
    {
        $('.tablesorter').trigger('pageSet',0);

    })

}); //close it too

回答by sealocal

As others have said, you must provide a function.

正如其他人所说,您必须提供一个功能。

One way is to take the existing code in question, and wrap it in an anonymous function:

一种方法是获取有问题的现有代码,并将其包装在一个匿名函数中:

$("#sortHeader").click( function() {
    $(".tablesorter")
    .bind("sortStart",function(e, table) 
        {
            $('.tablesorter').trigger('pageSet',0)
        })
    }
});

The other way is to give this function a name. If you've given your function a name and are still having trouble, ensure that you have passed the function name withoutparentheses.

另一种方法是给这个函数一个名字。如果您为函数指定了名称但仍有问题,请确保传递的函数名称不带括号。

$("#sortHeader").click( myEventHanler );  // <-- function name without parens

myEventHanler() {
    $(".tablesorter")
    .bind("sortStart",function(e, table) 
        {
            $('.tablesorter').trigger('pageSet',0)
        })
    }
}

回答by aliteralmind

I incorrectly placed the third parameter of the Underscore.js debouncefunction, which somehow caused the same error.

我错误地放置了Underscore.jsdebounce函数的第三个参数,这以某种方式导致了同样的错误。

Bad:

坏的:

$('#color_search_text').keyup(_.debounce(processSearch,
        MILLS_TO_IGNORE_SEARCH), true);

Good:

好的:

$('#color_search_text').keyup(_.debounce(processSearch,
        MILLS_TO_IGNORE_SEARCH, true));