infinite scrolling in EJS

浪子不回头ぞ 提交于 2020-01-06 05:41:20

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!