【发布时间】:2018-01-19 09:20:52
【问题描述】:
目前我正在使用此代码对 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,
}]
我该怎么做?
【问题讨论】:
-
请添加您的数据库提供的 JSON
-
@SandeepRanjan 我添加了返回的示例 JSON 数据
-
你自己回答累了吗?
-
我的解决方案有效吗?只是为了好,如果答案有效,您必须接受。