【问题标题】:Pass additional parameters to handsontable autocomplete source function将附加参数传递给可操作的自动完成源函数
【发布时间】:2018-10-30 19:44:35
【问题描述】:

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

但我想将 additional 参数传递给自动完成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
            },

documentationsource函数只接受两个参数(queryprocess),有谁知道我怎样才能传递额外的参数?

【问题讨论】:

    标签: handsontable


    【解决方案1】:

    您不能向source 函数添加参数。它不“接受”参数,它提供。 Handsontable 使用预定义的参数在内部调用此函数。

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

    类似:

    columns: [
      {
        type: 'autocomplete',
        source: function (query, process) {
          var rowId = this.row;
          var columnId = this.col;
    
          $.ajax({
            ... // do whatever you want
          });
        }
      }
    ]
    

    【讨论】:

    • 谢谢!.. 我没有找到你提到的ColumnSettings,但我确实设法像这样检索整行:const sourceRow = this.instance.getSourceData(); 从那里我可以选择我想要的任何列并通过它到服务器。
    猜你喜欢
    • 2011-09-20
    • 2015-12-06
    • 1970-01-01
    • 2016-04-26
    • 2014-11-27
    • 1970-01-01
    • 1970-01-01
    • 2015-07-19
    • 1970-01-01
    相关资源
    最近更新 更多