当前位置: 首页 > 后端技术 > Node.js

多人后台博客管理DAY08

时间:2023-04-03 20:45:11 Node.js

另一种分页方式:mongoose-sex-page(第三方模块)BLOG--源码目录└──model--数据库操作├──public--静态资源└──route--路由└──admin--Blogmanagement└──article.js--articlelistpage└──views--template└──admin--blogmanagementpagearttemplate└──article.art--articlelisttemplate└──app.js--Create一个网站服务article.js并导入mongoose-sex-page(第三方模块)实现分页npminstallmongoose-sex-page接受客户端传过来的页码//将文章集合的构造函数导入到当前fileconst{Article}=require('../../model/article');//导入mongoose-sex-page模块constpagination=require('mongoose-sex-page');module.exports=async(req,res)=>{//接收客户端传过来的页码constpage=req.query.page;//标识当前访问的是文章管理页面req.app.locals.currentLink='article';//page指定当前页面//suze指定每页显示的数据项数//display指定客户端显示的页数//exec向数据库发送查询请求//查询所有文章数据让articles=awaitpagination(Article).find().page(page).size(2).display(3).populate('author').exec();//res.send(文章);//渲染文章列表页面模板res.render('admin/article.art',{articles:articles});}article.art既然pagination是一个对象,那each应该改成.record,href也要改?页面样式转换与上一页和下一页类似,但使用了模板语法{{extend'./common/layout.art'}}{{block'main'}}{{include'./common/header.art'}}{{include'./common/aside.art'}}

文章

找到1篇文章发布新文章
ID标题发布时间作者操作{{eacharticles.records}}{{@$value._id}}{{$value.title}}{{dateFormat($value.publishDate,'yyyy-mm-dd')}}{{$value.author.username}}{{/each}}{{ifarticles.page>1}}
  • ?
  • {{/if}}{{每篇文章.display}}
  • {{$value}}}
  • {{/each}}{{ifarticles.page?</li>{{/if}}

    猜你喜欢