I am building short web app, and using axios.js to send data to database. But when I am fetching date from database, complete date is rendered, whereas I want only getDate(), getMonth() and getFullYear() to be working, but they doesn't seem like working.
This is windows 7 localhost server. I already tired calling it in different ways.
function itemTemplate(item) {
return `<li class="list-group-item list-group-item-action d-flex align-items-center justify-content-between"
style = "background-color: #cff0cc;
color: #498a17;
font-family: 'Kite One', sans-serif;">
<span class="item-text">Date: ${item.date.getDate()} / ${item.date.getMonth() +
1} / ${item.date.getFullyear()} - ${item.text}</span>
<div>
<button data-id="${
item._id
}" class="edit-me btn btn-primary btn-sm" style="background-color: darkgrey;border-color: grey;"><i class="fa fa-edit" style="width: 10px;"></i></button>
<button data-id="${
item._id
}" class="delete-me btn btn-danger btn-sm"><i class="fa fa-minus-circle" aria-hidden="true" style="width: 10px;"></i>
</button>
</div>
</li>`;
}
// Initial Page Load Render
let ourHTML = items
.map(function(item) {
return itemTemplate(item);
})
.join("");
document.getElementById("item-list").insertAdjacentHTML("beforeend", ourHTML);
// Create Feature
let createField = document.getElementById("create-field");
let createdDate = new Date();
document.getElementById("create-form").addEventListener("submit", function(e) {
e.preventDefault();
axios
.post("/create-item", { text: createField.value, date: createdDate })
.then(function(response) {
// Create the HTML for a new item
document
.getElementById("item-list")
.insertAdjacentHTML("beforeend", itemTemplate(response.data));
createField.value = "";
createField.focus();
})
.catch(function() {
res.send("Please try again later.");
});
});
Expected is, working of those three date functions, but error message shows up "item.date" is undefined at line 6