Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
如何在排序中使用变量?这是行不通的。
var order = "name"; var dir = "desc"; Board.sort({order : dir}).exec(function(err, results) { });
对于使用变量的值作为键,您应该使用括号[]
[]
Board.sort({[order] : dir}).exec(function(err, results) { }); <----- Using [] on order variable