用哈巴狗排序 JSON 个对象

Sort JSON object with pug

目前我正在使用此代码对 nodejs 代码中的数据进行排序。

const popularPlaces = await Places
.find({location: "New York"})
.sort( { locationscore: -1 } )

上面的代码找到位置 New York 并对具有较高 locationscore 的热门地点进行排序,然后转储到 popularPlaces。这样我就可以像这样在 pug/jade 模板上使用它:

each value in popularPlaces
  .h2 Top Popular Places #{value.placename}

但我想在 pug/jade 本身中进行排序...而不是通过 nodejs。

这是 popularPlaces

返回的 JSON
[{
    "placename": "Modern Stop", 
    "locationscore": 0.8734, 
},{
    "placename": "Next Coffee", 
    "locationscore": 0.807121, 
},{
    "placename": "Mahattan Bakery", 
    "locationscore": 0.899802, 
},{
    "placename": "Mainland Cafe", 
    "locationscore": 0.801271, 
},{
    "placename": "Combo Boo", 
    "locationscore": 0.808973, 
},{
    "placename": "Baker's Bakery", 
    "locationscore": 0.8123, 
}] 

我该怎么做?

尝试

- popularPlaces.sort(function(a, b){ return (a.locationscore > b.locationscore) ? 1 : ((b.locationscore > a.locationscore) ? -1 : 0); })

each value in popularPlaces
  .h2 Top Popular Places #{value.placename}