C# 中的实现代码如下,js 或者 typescript 中如何实现同样的排序效果?
var categories = flatCategories
.OrderBy(c => c.Order ?? short.MaxValue)
.ThenBy(c => c.Title);
通过下面的代码解决了
const categories = flatCategories.sort((x, y) => {
const order1 = x.order ?? DEFAULT_ORDER;
const order2 = y.order ?? DEFAULT_ORDER;
if (order1 > order2) {
return 1;
} else if (order1 < order2) {
return -1;
} else {
return x.title.localeCompare(y.title);
}
});