1

如何在排序中使用变量?这是行不通的。

var order = "name";
var dir = "desc";
Board.sort({order : dir}).exec(function(err, results) { });
4

1 回答 1

0

对于使用变量的值作为键,您应该使用括号[]

Board.sort({[order] : dir}).exec(function(err, results) { }); <----- Using [] on order variable
于 2021-03-09T13:36:07.440 回答