【问题标题】:Tabulator.js accessibility by id does not workTabulator.js 的 id 可访问性不起作用
【发布时间】:2019-08-05 08:32:06
【问题描述】:

全局变量对制表器表的可访问性工作正常,但我不能真正使用全局变量,因为我正在动态生成新表。

我只想通过容器 ID 访问表。

下面的代码通过示例 (http://tabulator.info/examples/4.3#adddel) 提供的全局变量“table”和 ID 显示可访问性,但不起作用。

请参阅我的 JSFiddle 示例:https://jsfiddle.net/vs43re6p/41/

$('#button').click(function() {
    table.addRow({});
});

$('#button2').click(function() {
    $("#example-table").tabulator("addRow", {});
});

我做错了什么?

【问题讨论】:

    标签: javascript tabulator


    【解决方案1】:

    如果你想使用 jQuery 选择,你需要安装 Tabulator jQuery 包装器:

    http://tabulator.info/docs/4.3/install#setup-jquery

    【讨论】:

      【解决方案2】:

      也许是这样的......

      $('#button2').click(function() {
          const table = new Tabulator("#example-table");
          table.addRow({});
      });
      

      (function() {
          const table = new Tabulator("#example-table");
      
          $('#button2').click(function() {
              table.addRow({});
          });
      })();
      

      【讨论】:

      • 这个表不是还在被全局变量访问吗?问题是,我喜欢:“table1,table2,table3”等,它们不应该接收全局变量。 Lib说提供了一种通过id访问表的方法,但是不起作用=(
      • 我不知道我是否正确,但是:这两个示例都包装在一个函数中,因此 table 不是全局的。你有更多的代码给我们吗?
      【解决方案3】:

      只要您使用的是 Tabulator 4.5 或更高版本,您就可以使用 Tabulator 原型上的 findTable 函数按元素 ID 查找表格

      var table = Tabulator.prototype.findTable("#example-table")[0]; // find table object for table with id of example-table
      

      findTable 函数将返回匹配表的数组。如果没有找到匹配,它将返回false

      详情请见Options Documentation

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2021-10-31
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2018-03-22
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多