我按照这里的文档实现了HandsOnTable自动完成ajax:https://docs.handsontable.com/3.0.0/demo-autocomplete.html#strict-ajax
但我想将额外的参数传递给autocomplete 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
函数只接受两个参数(query
和process
),有人知道如何传递额外的参数吗?
发布于 2018-06-02 04:12:39
不能向source
函数添加参数。它不“接受”参数,而是提供参数。此函数由Handsontable使用预定义参数在内部调用。
但是你仍然可以访问你正在寻找的数据。检查调用source
函数时所使用的上下文。它是一个ColumnSettings
对象,其中包含(以及其他)列和行ids。
类似于:
columns: [
{
type: 'autocomplete',
source: function (query, process) {
var rowId = this.row;
var columnId = this.col;
$.ajax({
... // do whatever you want
});
}
}
]
https://stackoverflow.com/questions/50443974
复制相似问题