file()
自:编辑器 1.5
获取已上传文件的信息。
请注意 - 此属性需要 DataTables 的 编辑器 扩展。
说明
该方法是 file()
方法的别名,该方法完全接受相同参数并返回相同的结果。在使用 DataTables API 方法而不是编辑器较容易的情况下,出于方便,DataTables API 上提供了此别名。
请参阅 file()
文档,以获取此方法的详细信息。
类型
示例
使用 file()
在数据表列和编辑器表单中显示图片
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152$(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
});
});
相关
以下选项直接相关,在您的应用程序开发中也可能有用。
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.