【发布时间】:2022-01-14 08:46:42
【问题描述】:
我试图让搜索结果显示在我的 html 页面上,并最终显示在一个表单中。问题是我的 .map 函数,当我运行代码时,我只能在控制台中看到我正在搜索的记录。 有什么建议? 我正在使用 nodejs、express 和 html。
//Get sop number by combining url with data from input box
getInfo();
function getInfo() {
document.getElementById("form");
button.onclick = function (e) {
e.preventDefault();
const url = "http://localhost:6600/api/sopId";
let sopSearch = document.getElementById("sop");
fetch(`${url}/${sopSearch.value}`, {
method: "GET",
})
.then((response) => {
console.log(response);
if (!response.ok) {
throw Error("ERROR");
}
return response.json();
})
.then((data) => {
console.log(data);
const html = data.data.map((receipts) => {
return `<p>SopNumber ${receipts.SOPNUMBE}</p>`;
});
console.log(html);
document
.querySelector("#app")
.insertAdjacentElement("afterbegin", `<h1`);
})
.catch((error) => {
console.log(error);
});
};
}
【问题讨论】: