Browse Source

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

close https://gitee.com/layui/layui/issues/I8JAC1
pull/1504/head
morning-star 11 months ago committed by GitHub
parent
commit
567a1e70c1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 5
      docs/upload/detail/options.md
  2. 4
      src/modules/upload.js

5
docs/upload/detail/options.md

@ -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); // 得到文件对象
}
}
```

4
src/modules/upload.js

@ -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);
});

Loading…
Cancel
Save