如果使用getscript加载,如何让tablesorter工作。

时间:2015-06-29 15:06:40

标签: jquery tablesorter

我使用jquery .getscript加载tablesorter。

WOI_.loadeddatatables = false;

$.getScript("//cdnjs.cloudflare.com/ajax/libs/jquery.tablesorter/2.22.1/js/jquery.tablesorter.min.js").done(function(script, textStatus ){   
    console.log("text status " + textStatus);
    WOI_.loadeddatatables = true;

    }).fail(function(jqxhr, settings, exception){

      console.log(jqxhr);

});

稍后我会有一些代码检查WOI_.loadeddatatables是否为true,如果是,则调用sorttable。

WOI_.functions.sorttable = function(el){
     console.log(el);

     el.tablesorter(); 
}

if(WOI_.loadeddatatables){
     WOI_.functions.sorttable($("#userwidgetstats"));
}

我的文本状态是成功的,因此脚本已加载,如果我在资源面板中检查它,我也可以看到它已加载。

console.log(el)给了我一个长度为1的jquery元素。

该表有一个似乎是tablesorter正在寻找的结构 - 一个thead和一个tbody,thead有tr和多个元素,tbody有多个tr。无论如何,如果表结构存在一些问题,我预计它会引发一些其他错误。

所以看起来像tablesorter似乎不喜欢被getscript加载。是对的吗?

0 个答案:

没有答案