var list = {};
var formDataObj = new formData($('#someForm')[0]);
for (var key of formDataObj.keys()) {
list[key] = formDataObj.get(key);
}
以上在require打包时报错了,推荐以下方法:
var entriesObj = formData.entries();
var loopEntrie = entriesObj.next();
var loopValue = "";
/** done 为 true 时 表示已经遍历完毕*/
while (!loopEntrie["done"]) {
//loopEntrie对象的value属性以数组形式存储了一对key/value,数组下标0为key,下标1为value
loopValue = loopEntrie["value"];
defOpt['postData'][loopValue[0]] = loopValue[1];
loopEntrie = entriesObj.next();
}