我想将FormData带到控制台以检查密钥和值。
IP := $(shell docker-machine ip default)
$(warning IP=$(IP))
当我在登录控制台时,无处可查看密钥和值。
你能给我一些小费吗?
答案 0 :(得分:1)
答案 1 :(得分:1)
利用Web Workers API
,FormData.entries()
的方法;另见Using Web Workers
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8" />
<title>MDN Example - Embedded worker</title>
<script type="text/js-worker">
// This script WON'T be parsed by JS engines
// because its mime-type is text/js-worker.
// var myVar = "Hello World!";
var key = "key1";
var value = "value1";
// myVar.append('key1', 'value1');
// Rest of your worker code goes here.
</script>
<script type="text/javascript">
// This script WILL be parsed by JS engines
// because its mime-type is text/javascript.
function pageLog (sMsg) {
// Use a fragment: browser will only render/reflow once.
var oFragm = document.createDocumentFragment();
oFragm.appendChild(document.createTextNode(sMsg));
oFragm.appendChild(document.createElement("br"));
document.querySelector("#logDisplay").appendChild(oFragm);
}
</script>
<script type="text/js-worker">
// This script WON'T be parsed by JS engines
// because its mime-type is text/js-worker.
onmessage = function (oEvent) {
var f = new FormData();
f.append(key, value);
for(var pair of f.entries()) {
postMessage(pair[0] + ", " + pair[1]);
}
};
// Rest of your worker code goes here.
</script>
<script type="text/javascript">
// This script WILL be parsed by JS engines
// because its mime-type is text/javascript.
// In the past...:
// blob builder existed
// ...but now we use Blob...:
var blob = new Blob(
Array.prototype
.map.call(
document.querySelectorAll("script[type=\"text\/js-worker\"]")
, function (oScript) { return oScript.textContent; })
, {type: "text/javascript"});
// Creating a new document.worker property
// containing all our "text/js-worker" scripts.
document.worker = new Worker(window.URL.createObjectURL(blob));
document.worker.onmessage = function (oEvent) {
pageLog("Received: " + oEvent.data);
};
// Start the worker.
window.onload = function() { document.worker.postMessage(""); };
</script>
</head>
<body><div id="logDisplay"></div></body>
</html>
答案 2 :(得分:1)
// Log entries of a FormData object to the console as an object.
export const logFormData = (formData) => {
const entries = formData.entries();
const result = {};
let next;
let pair;
while ((next = entries.next()) && next.done === false) {
pair = next.value;
result[pair[0]] = pair[1];
}
console.log(result);
};