【发布时间】:2023-04-05 22:08:01
【问题描述】:
我在表格中列出了用户列表。 活跃用户应该排在非活跃用户之上。
我正在尝试使用 lodash sortBy 函数制作这个 sort,但没有成功。
userArray 的外观如下:
const userArray [
{
// I need to show users which have disabled = false first
// and then users with disabled = true
disabled: true, // <==========
email: "hgaither@cmregent.com",
firstName: "Harriet",
lastName: "Gaither",
role: "claimsHandlerSupervisor",
userId: "03VFpxtMWgY1jKDHDLcrWSw1qzx1",
},
{
disabled: false, // <===========
email: "hgaither@cmregent.com",
firstName: "Harriet",
lastName: "Gaither",
role: "claimsHandlerSupervisor",
userId: "03VFpxtMWgY1jKDHDLcrWSw1qzx1",
},
]
这里是带有用户数组和 sortBy loadsh 函数的代码笔: https://codepen.io/nikolatrajkovicq/pen/pGXdpM?editors=1112
欢迎任何建议。
【问题讨论】:
-
你可以只创建 2 个数组,包含启用和禁用用户,而不是在启用结束时连接禁用,这将使禁用用户出现在最后(但不按任何顺序排序)
标签: javascript arrays reactjs