【问题标题】:Why is data("selectable") returning "undefined"?为什么数据(“可选择”)返回“未定义”?
【发布时间】:2013-06-08 17:02:30
【问题描述】:

我遵循以下问题来实现“全选”功能: How to programmatically select selectables with jQuery UI?

全选按钮在 ._mouseStop 命令的位置上完美运行,然后它只是吐出错误:

Uncaught TypeError: Cannot call method '_mouseStop' of undefined 

以下是代码的相关部分:

第一步:这个页面有四个列表,四个都使用可选插件

//Make all four lists selectable
$("#selectNewTweets").selectable();
$("#selectApprovedTweets").selectable();
$("#selectDeclinedTweets").selectable();
$("#selectUndecidedTweets").selectable();

第 2 步:批量注册所有“全选”按钮(每个列表一个)

//click a "Select All" button
$("[id^=btnSelectAll]").click(function(e){
    var id = $(this).attr('id');
    var list = id.substring(
        "btnSelectAll".length,
        id.length);
    //select all elements in target list
    $("#select"+list+"Tweets > li").each(function(index){
        $(this).removeClass('ui-selected');
        $(this).addClass("ui-selecting");
    });

    $("#select"+list+"Tweets").data("selectable")._mouseStop(null);
});

当我单击任何“全选”按钮时,里面的元素都获得了“ui-selecting”类,因此 .each() 语句运行良好。但是,一旦到达 ._mouseStop() 行,它就会抛出我上面提到的异常。

任何想法是什么导致了异常?

【问题讨论】:

    标签: jquery selectable


    【解决方案1】:

    如果您注意到 this comment 为您引用的 StackOverflow 问题的选定答案,它表示对于更高版本的 jQuery UI 库,您应该使用 .data("ui-selectable") 而不是 .data("selectable")。希望这就是您遇到错误的原因,因为我认为您的代码没有其他问题。

    【讨论】:

      猜你喜欢
      • 2020-03-28
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-10-24
      • 2021-12-11
      • 2019-08-21
      相关资源
      最近更新 更多