sort or shuffle list during pug iteration?

A.D*_*A.D 1 javascript node.js pug

I am trying to perform array operations such as concat, shuffle, and sort during pug iteration.

pug文档中,这是可能的:

ul
  each val in [1, 2, 3, 4, 5]
    li= val
Run Code Online (Sandbox Code Playgroud)

但是像这样的事情呢:

ul
  each val in sort(list_obj1 + list_obj2) // i would also like to shuffle a list here...
    li= val
Run Code Online (Sandbox Code Playgroud)

在我的情况,list_obj1list_obj2从一个节点JS服务器发送。我知道我可以在服务器端计算排序的连接列表。但是出于各种实现原因,我需要在客户端计算它。

我怎样才能做到这一点?另外,是否可以underscore用于数组操作?

Mic*_*ski 5

您可以将 pug 与 JS 混合使用,因此没有什么是不可能的:

- var list = [1,2,3,4,5]
- list.sort((a,b)=>{return Math.random()-0.5})
each val in list
  div= val
Run Code Online (Sandbox Code Playgroud)

钢笔