当前位置:网站首页>FormData的使用
FormData的使用
2022-07-26 23:18:00 【kilito_01】
export default {
toFormData(formModel) {
var formData = new FormData()
for (var name in formModel) {
var value = formModel[name]
this.setNameValue({
prefix: name, value, formData })
}
return formData
},
setNameValue({
prefix, value, formData }) {
if (value === undefined || value == null) {
return
}
if (typeof value === 'object') {
if (value instanceof FileList) {
var fileList = value
for (let i = 0; i < fileList.length; i++) {
formData.append(prefix, fileList[i])
}
} else if (value instanceof Array) {
if (value.length === 0) {
return
}
for (let i = 0; i < value.length; i++) {
this.setNameValue({
prefix: prefix + '[' + i + ']', value: value[i], formData })
}
} else {
for (var key in value) {
this.setNameValue({
prefix: prefix + '.' + key, value: value[key], formData })
}
}
} else {
formData.append(prefix, value)
}
}
}
边栏推荐
- uni-app上自定义微信小程序的tabbar
- 【自此文之后,学习链表一片坦途】
- [do you know cache - fully understand cache]
- Little sister's notes: how do I learn simple source code to expand my horizons
- Record the nth SQL exception
- Open the door of programming
- HCIP-第五天-OSPF扩展配置实验
- Interesting C language
- After working in Tencent testing post for 5 years, I was ruthlessly dismissed in July, trying to wake up my brother who was still paddling
- Is it useful to lie down with your eyes closed when you can't sleep?
猜你喜欢

Hcip OSPF comprehensive experiment

消息队列学习 -- 概念

How many holes have you stepped on in BigDecimal?

OSPF summary (mind map)

30岁被裁,我想明白的几件事....

【你了解Cache吗——全面理解高速缓冲存储器】

C language - assignment operator, compound assignment operator, self increasing and self decreasing operator, comma operator, conditional operator, goto statement, comment

Writing a pacesetter frequently -- yunxiaojing

After ten years of testing, I want to say to my friends who are still confused: one thing is to do a good job in personal planning

Sort the three integers from large to small (introduce various methods in detail)
随机推荐
通达信开户安全么
Talk about the metrics of automated testing
Northeast Securities stock online account, is it safe to open an account on your mobile phone
Witness that the "decoding 2022 strong star of China's network security" is about to set sail
小姐姐笔记:我是如何学习简单源码拓展视野的
【洋哥带你玩转线性表(一)——顺序表】
东北证券股票网上开户,手机上开户安全吗
How to judge whether a number is odd or even?
Redis五种基本数据结构
Plato Farm有望通过Elephant Swap,进一步向外拓展生态
静态路由基本配置 实现全网可达
【力扣】1859.将句子排序
Hcip OSPF knowledge summary
Towhee 每周模型
How many holes have you stepped on in BigDecimal?
Hcip day 1
砺夏行动|源启数字化:既有模式,还是开源创新?
[do you know cache - fully understand cache]
【斐波那契数列及螺线 基于C语言】
静态路由综合实验