【问题标题】:How do I continue do things after finish footable initialize?完成footable初始化后如何继续做事?
【发布时间】:2020-06-04 18:12:13
【问题描述】:

我为我的数据表使用名为 fooTable 的查询插件 (http://fooplugins.github.io/FooTable/)

下面是我初始化数据表的代码...

jQuery(function($){
  $('.table').footable({
      "paging": { "size": 15 },
      // "toggleColumn": "last",
      "showToggle": false,
      "columns": $.get('/footable/js/columns.json'),
      "rows": $.get('/footable/js/rows.json')
  })
})

我的问题是初始化完成后怎么办?

我试试

jQuery(function($){
  $('.table').footable({
      "paging": { "size": 15 },
      // "toggleColumn": "last",
      "showToggle": false,
      "columns": $.get('/footable/js/columns.json'),
      "rows": $.get('/footable/js/rows.json')
  })
  .done(function(){
    alert('do something');
  })
})

但它不起作用。

【问题讨论】:

    标签: javascript jquery promise footable


    【解决方案1】:

    您应该使用postinit.ft.table 事件以及@Roamer-1888 提到的on 选项。 (您可以单击任何选项以查看如何使用它的小示例。)

    jQuery(function($) {
        $('.table').footable({
            // your other options
            'on': {
                'postinit.ft.table': function(e, ft) {
                    /*
                     * e: The jQuery.Event object for the event.
                     * ft: The instance of the plugin raising the event.
                     */
                    // all initialized - do stuff here
                }
            }
        });
    });
    

    或者,插件构造函数的第二个参数是一个就绪回调,因此您只需提供一个函数即可在一切完成后执行。

    jQuery(function($) {
        $('.table').footable({
            // your options
        }, function(ft){
            /*
             * ft: The instance of the plugin raising the event.
             */
            // all initialized - do stuff
        });
    });
    

    【讨论】:

    • 除了这里的最后一个选项和第二个参数外,我无法在所有这些答案中得到任何工作,对于其他任何想要在初始化所有内容后做事情的人来说,这就是你想要的。
    • 另外,还有一个ready.ft.table 事件,在这种情况下很有用。
    【解决方案2】:

    使用postinit.ft.table 事件。见http://fooplugins.github.io/FooTable/docs/jsdocs/FooTable.html#.event:Table%2522postinit.ft.table%2522

    postinit.ft.table 事件在任何组件初始化之后但在第一次绘制表格之前引发。在此事件上调用 preventDefault 将禁用表格的初始绘制。

    另外,postdraw.ft.table 是您可能想要的。

    关于如何使用它

    我对它不是很熟悉。所以试试吧。如果它不起作用,请告诉我。

    .when('postinit.ft.table', function(e, ft){
        //ok
    })
    

    【讨论】:

    • 我如何使用这个活动?
    • @aBloomer 答案已修改。看到它
    • 真的很感激。
    【解决方案3】:

    FooTable 文档很难理解,因为它没有过多的示例。

    我认为@turle 建议使用“postinit.ft.table”事件是一个很好的建议,但是我看不出.when('postinit.ft.table', function(e, ft){ /* do something */ }) 是正确的语法。

    据我从here 收集到的信息,事件处理程序是使用“on”选项附加的。

    试试:

    jQuery(function($) {
        $('.table').footable({
            'paging': { 'size': 15 },
            // "toggleColumn': "last",
            'showToggle': false,
            'columns': $.get('/footable/js/columns.json'),
            'rows': $.get('/footable/js/rows.json'),
            'on': {
                'postinit.ft.table': function(e, ft) {
                    /*
                     * e: The jQuery.Event object for the event.
                     * ft: The instance of the plugin raising the event.
                     */
                    // all initialized - do stuff here
                }
            }
        });
    });
    

    【讨论】:

      【解决方案4】:

      试试'ready.ft.table'

      类似

      jQuery(function($){
          $('.table').footable({
          "on": {
              "ready.ft.table": function(e, ft){
                  // bind to the plugin initialize event to do something
              }
          }
         });
      });
      

      【讨论】:

        猜你喜欢
        • 2016-10-18
        • 2021-12-30
        • 1970-01-01
        • 1970-01-01
        • 2010-11-08
        • 2014-09-01
        • 1970-01-01
        • 1970-01-01
        • 2019-06-30
        相关资源
        最近更新 更多