Javascript 未捕获(承诺中)TypeError:(中间值)。toLocalDateString不是Stats.js:62中的函数
toLocalDateString-->toLocalDateStringJavascript 未捕获(承诺中)TypeError:(中间值)。toLocalDateString不是Stats.js:62中的函数,javascript,node.js,reactjs,compiler-errors,frontend,Javascript,Node.js,Reactjs,Compiler Errors,Frontend,toLocalDateString-->toLocalDateString toLocalTimeString-->toLocalTimeString最初,数组中没有值。请尝试customerList.length&&customerList.map(…拼写为locale,但不是local,因为您可以指定类似“en-CA”的区域代码。谢谢,它可以工作。我的个人资料中还有一个问题,您认为您能帮上忙吗? function Stats() { const [customerList, setCus
toLocalTimeString-->toLocalTimeString最初,数组中没有值。请尝试
customerList.length&&customerList.map(…
拼写为locale,但不是local,因为您可以指定类似“en-CA”的区域代码。谢谢,它可以工作。我的个人资料中还有一个问题,您认为您能帮上忙吗?
function Stats() {
const [customerList, setCustomerList] = useState([]); //store all that information of the database in a list
//make an axios request to get information from database
const getCustomers = () => {
Axios.get("http://localhost:3001/customers").then((response) => {
//console.log("successfully retrieved customers list from database");
console.log(response.data);
setCustomerList(response.data);
});
};
{/*}
const [currentTime, setCurrentTime] = useState(1);
useEffect(() => {
fetch("/time")
.then((res) => res.json())
.then((data) => {
setCurrentTime(data.time);
});
}, []);
useEffect(() => {
fetch("/time")
.then((res) => res.json())
.then((data) => {
const dateStr = new Date(data.time).toLocalDateString('en-CA');
const timeStr = new Date(data.time).toLocalTimeString();
const dateTime = `${dateStr} ${timeStr}`;
setCurrentTime(dateTime);
});
}, []);
*/}
return (
<div>
<Navbar />
<div className="container">
<h1>Dashboard</h1>
<button onClick={getCustomers}>Show Dashboard</button>
</div>
<table className="customertable">
<thead>
<tr>
<th>S/N</th>
<th>Customer Name</th>
<th>Customer Email</th>
<th>Counts of Visit</th>
<th>Latest Time of Visit</th>
<th>Contacted?</th>
</tr>
</thead>
<tbody>
{customerList.map((val, key) => {
const dateStr = new Date(val.latest_time_of_visit).toLocalDateString('en-CA');
const timeStr = new Date(val.latest_time_of_visit).toLocalTimeString();
const dateTime = `${dateStr} ${timeStr}`;
return (
<tr>
<td>{val.ID}</td>
<td>{val.name}</td>
<td>{val.email}</td>
<td>{val.counts_of_visit}</td>
<td>{dateTime}</td>
<td>{val.contacted}</td>
</tr>
);
},)}
</tbody>
</table>
</div>
);
}
export default Stats;
const dateStr = new Date(val.latest_time_of_visit).toLocalDateString('en-CA');