将附加参数传递给 handsontable 自动完成源函数

Pass additional parameters to handsontable autocomplete source function

我正在实施 HandsOnTable 自动完成 ajax,如此处所述:https://docs.handsontable.com/3.0.0/demo-autocomplete.html#strict-ajax

但我想将 附加 参数传递给自动完成 source 函数,类似于下面的 row.id

hot3 = new Handsontable(container3, {
    data: getCarData(),
    colHeaders: ['Car', 'Year', 'Chassis color', 'Bumper color'],
    columns: [
      {
        type: 'autocomplete',
        source: function (query, process, row.id) {
          $.ajax({
            //url: 'php/cars.php', // commented out because our website is hosted as a set of static pages
            url: 'scripts/json/autocomplete.json',
            dataType: 'json',
            data: {
              query: query
            },

documentation开始,source函数只接受两个参数(queryprocess),谁知道如何传递额外的参数?

您不能向 source 函数添加参数。它没有"accept"参数,它提供了。此函数由 Handsontable 使用预定义参数在内部调用。

但您仍然可以访问您正在寻找的数据。检查调用 source 函数的上下文。这是一个 ColumnSettings 对象,其中包含(除其他外)列和行 ID。

类似于:

columns: [
  {
    type: 'autocomplete',
    source: function (query, process) {
      var rowId = this.row;
      var columnId = this.col;

      $.ajax({
        ... // do whatever you want
      });
    }
  }
]