{hero}

file()

自:编辑器 1.5

获取已上传文件的信息。
请注意 - 此属性需要 DataTables 的 编辑器 扩展。

说明

该方法是 file() 方法的别名,该方法完全接受相同参数并返回相同的结果。在使用 DataTables API 方法而不是编辑器较容易的情况下,出于方便,DataTables API 上提供了此别名。

请参阅 file() 文档,以获取此方法的详细信息。

类型

函数 file(table, id)

说明

获取已通过编辑器 (uploaduploadMany) 上传的文件的信息。返回的信息由服务器端 Upload 类的 db() 方法配置方式确定(如果已使用此方法)。有关此方法的详细信息,请参阅 PHP.NET

参数
返回值

所选文件的信息,或 undefined(如果未找到)。

示例

使用 file() 在数据表列和编辑器表单中显示图片

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
$(document).ready(function () {
    var editor = new DataTable.Editor({
        ajax: '../php/upload.php',
        table: '#example',
        fields: [
            {
                label: 'First name:',
                name: 'users.first_name'
            },
            {
                label: 'Last name:',
                name: 'users.last_name'
            },
            {
                label: 'Image:',
                name: 'users_files.fileId',
                type: 'upload',
                display: function (fileId) {
                    return '<img src="' + table.file('files', fileId).web_path + '"/>';
                }
            }
        ]
    });
 
    var table = new DataTable('#myTable', {
        ajax: '../php/upload.php',
        columns: [
            { data: 'users.first_name' },
            { data: 'users.last_name' },
            { data: 'users.phone' },
            { data: 'sites.name' },
            {
                data: 'users_files.fileId',
                render: function (fileId) {
                    return fileId
                        ? '<img src="' + table.file('files', fileId).web_path + '"/>'
                        : 'No image';
                }
            }
        ],
        layout: {
            topStart: {
                buttons: [
                    { extend: 'create', editor: editor },
                    { extend: 'edit', editor: editor },
                    { extend: 'remove', editor: editor }
                ]
            }
        },
        select: true
    });
});

相关

以下选项直接相关,在您的应用程序开发中也可能有用。

Comments (0)

No comments posted for this page yet. Be the first to contribute!

Post new comment

Contributions in the form of tips, code snippets and suggestions for the above material are very welcome. To post a comment, please use the form below. Text is formatted by Markdown.

To post comments, please sign in to your DataTables account, or register:

Any questions posted here will be deleted without being published.
Please post questions in the Forums. Comments are moderated.