简体   繁体   English

如何在渲染中显示而不是在node.js中显示console.log

[英]How do i display on render instead of console.log in node.js

I have already sorted the objects like the link below. 我已经对对象进行了排序,例如下面的链接。 My next step is to be able to use the sorted object so i can use it in to display on my render rather than just console.log() . 我的下一步是能够使用排序的对象,这样我就可以使用它来显示在我的渲染器上,而不仅仅是console.log()

I'm not sure if putting it back into an object is the approach. 我不确定是否将其放回对象中。 Would appreciate if anyone can help me out. 如果有人可以帮助我,将不胜感激。 Thanks 谢谢

 var byLikes = [ { name: 'herman', Like: 5 }, { name: 'tabitha', Like: 3 }, { name: 'juags', Like: 1 }, { name: 'ukiq', Like: 4 }, { name: 'limau', Like: 10 }, { name: 'kwe', Like: 6 } ]; byLikes.sort(sortByLike); function sortByLike(a, b) { var result = 0; if (a.Like > b.Like) { result = 1; } if (b.Like > a.Like) { result = -1; } return result; } byLikes.forEach(function (cat) { console.log(cat); }); res.render('reload', { imglikes: sortedlikedhere, postername: sortednamehere }); 

byLikes can be passed to render method as below. 可以将byLikes传递给render方法,如下所示。 In the template, it can be accessed via imglikes property. 在模板中,可以通过imglikes属性访问它。

res.render('reload', {
  imglikes: byLikes, 
  postername: sortednamehere
});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM