我想将值传递给dtOptions.buttons的函数(例如dt,node,config)
角度6
如何将dtOptions.buttons的值传输到函数(e,dt,node,config)?
import { Component, OnInit } from '@angular/core';
@Component({
selector: 'app-buttons-extension',
templateUrl: 'buttons-extension.component.html'
})
export class ButtonsExtensionComponent implements OnInit {
// Must be declared as "any", not as "DataTables.Settings"
dtOptions: any = {};
val=10;
ngOnInit(): void {
this.dtOptions = {
ajax: 'data/data.json',
columns: [{
title: 'ID',
data: 'id'
}, {
title: 'First name',
data: 'firstName'
}, {
title: 'Last name',
data: 'lastName'
}],
// Declare the use of the extension in the dom parameter
dom: 'Bfrtip',
// Configure the buttons
buttons: [
'columnsToggle',
'colvis',
'copy',
'print',
'excel',
{
text: 'Some button',
key: '1',
action: function (e, dt, node, config) {
alert(this.val);
}
}
]
};
}
}
console.log: 未定义
答案 0 :(得分:0)
您可以尝试以下操作:
{
text: 'Some button',
key: '1',
action: (e, dt, node, config) => this.methodName(e, dt, node, config) {
alert(this.val);
}