const getFile = () => {
const files = dialog.showOpenDialog({
properties: ['openFile'],
filters: [
{ name: 'Markdown', extensions: ['md', 'mdown', 'markdown'] },
{ name: 'Text', extensions: ['txt', 'text'] },
],
});
对于我的过滤器,应用程序仅将第一个对象用作正确的过滤器。例如,当首先列出markdown时,我只能选择markdown文件,而当首先列出文本对象时,我只能选择文本文件。基于文档,我应该能够像这样创建过滤器
{
filters: [
{ name: 'Images', extensions: ['jpg', 'png', 'gif'] },
{ name: 'Movies', extensions: ['mkv', 'avi', 'mp4'] },
{ name: 'Custom File Type', extensions: ['as'] },
{ name: 'All Files', extensions: ['*'] }
]
}
我想念什么?
答案 0 :(得分:-1)
电子对话框过滤器对象将过滤器作为带有文件扩展名数组的过滤器对象的数组。当我们添加多个过滤器对象时,它就像带有定义的过滤器对象名称的过滤器列表一样显示。作为简单的下拉列表绑定。
例如-
示例1-当我们使用下面的过滤器对象“ filters”时,-
const openDialogOptions: OpenDialogOptions = {
defaultPath: '',
filters: [
{ name: "All Files", extensions: ["*"] },
{ name: 'Word Template', extensions: ["dot", "dotx"] },
{ name: 'Word Document', extensions: ["doc", "docx"] },
{ name: 'MS Perfect', extensions: ["wpt"] }],
properties: ['openFile']
}
它将绑定下拉列表中的过滤器列表,如下所示-
示例2-当我们使用下面的过滤器对象“ filters”时,-
const openDialogOptions: OpenDialogOptions = {
defaultPath: '',
filters: [
{ name: 'Word Template', extensions: ["doc", "docx","dot", "dotx"] },
{ name: 'MS Perfect', extensions: ["wpt"] }],
properties: ['openFile']
}
它将绑定下拉列表中的过滤器列表,如下所示-