我需要在我的桌子上添加“上传”按钮:
下面是我使用dtOption的TS文件:
...
order: [[3, 'desc']],
dom: 'Blfrtip',
stateSave: true,
buttons: [
this.datatableServices.getButtons(),
{
text: '<i class="material-icons" title="Supprimer">delete</i>',
className: 'btn btn-danger btn-fab btn-fab-mini',
action: function (e, dt, node, config) {
that.deleteSelection();
}
},
{
text: '<i class="material-icons" title="Modifier">edit</i>',
className: 'btn btn-success btn-fab btn-fab-mini',
action: function (e, dt, node, config) {
that.editSelection();
}
},
{
text: '<i class="material-icons" title="Nouveau">add</i>',
className: 'btn btn-warning btn-fab btn-fab-mini',
action: function (e, dt, node, config) {
that.selectedList = [];
that.launchModal(that.selectedList,1);
}
},
{
text: '<i class="material-icons" title="Importer">archive</i>',
className: 'btn btn-info btn-fab btn-fab-mini',
action: function (e, dt, node, config) {
let fileSelector = $('<input #fileInput onchange="importInternes($event)" type="file" >');
fileSelector.click();
}
}
]正如你所看到的,我已经设置了按钮,这是完美的工作。
最后的问题是,我得到
(索引):1未定义的ReferenceError: importInternes未定义为HTMLInputElement.onchange ((索引):1)
但是,如果我调用“警报”函数(例如,而不是"importInternes“),它就能工作。
如何调用我的"importInternes“方法?
发布于 2020-07-16 07:41:05
找到了!
在这里,解决方案:
{
text: '<i class="material-icons" title="Importer">archive</i>',
className: 'btn btn-info btn-fab btn-fab-mini',
action: function (e, dt, node, config) {
let fileSelector = $('<input id="fileInput" type="file">');
fileSelector.click();
fileSelector.change(function(){
if (fileSelector[0].files.length > 0) {
that.importInternes(fileSelector[0].files[0].name);
}
});
}
}https://stackoverflow.com/questions/62919273
复制相似问题