feat(upload): 加强 data 选项的函数写法,支持获取文件相关数据 (#1494)

close https://gitee.com/layui/layui/issues/I8JAC1
pull/1504/head
morning-star 2023-12-25 13:22:50 +08:00 committed by GitHub
parent 6abb1eedd8
commit 567a1e70c1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 8 additions and 1 deletions

View File

@ -74,6 +74,11 @@ data: {
data: {
id: function(){
return $('#id').val();
},
id2: function(index, file){ // 参数支持。2.9.3+
// 注:当 unified:true 和 ie8/9 下,参数无效
console.log(index); // 得到文件索引
console.log(file); // 得到文件对象
}
}
```

View File

@ -279,7 +279,9 @@ layui.define(['lay', 'layer'], function(exports){
// 追加额外的参数
layui.each(options.data, function(key, value){
value = typeof value === 'function' ? value() : value;
value = typeof value === 'function'
? sets.unified ? value() : value(sets.index, sets.file)
: value;
formData.append(key, value);
});