问题
As the title says I am trying to implement infinite scroll on my page using ejs.
Right now I have it set to render a finite number of items from my database to the page.
Express JS side:
app.get(`/`, (req, res) => {
database.find({}, (err, items) => {
if (!err){
res.render("home",{cards:items});
} else {
console.log(err);
}
}).limit(20);
});
On the the EJS side I have the items then displayed in EJS by means of a forEach loop.
<%cards.forEach((i) => {%>
<p><%=i.contents%></p>
<%})%>
Which loads the finite number of resources.
Now using Socket io, I'm able to send a request for additional content
Client
socket.emit("loadmore", parseInt(count));
server
socket.on("loadmore", (count) => {
linkscr.amazon.find({},(e,found)=>{
if(!e){
const data = found;
socket.emit("loadmore", data);
}
}).skip(count).limit(10);
});
Now I have another ten items I want to try to push into the running for loop, but as far as I know, I can not see how to do so as I am running the function in for the request function. Is there a way for me to do this?
来源:https://stackoverflow.com/questions/58828185/infinite-scrolling-in-ejs