[英]how to specify two values for the second argument for lodash orderBy?
Could anyone help me how to realize the following case: I have an array with objects, every object has field createEL
, and some of them have updateEl
.谁能帮助我如何实现以下情况:我有一个包含对象的数组,每个 object 都有字段
createEL
,其中一些有updateEl
。
My task is to sort all the elements with updateEl
if it's available, otherwise sort by createEl
我的任务是使用
updateEl
对所有元素进行排序(如果可用),否则按createEl
排序
my current option:我目前的选择:
orderBy(myData, ['updateEl','createEl'], 'desc)
I wonder if it's correct for cases if I don't have updateEl
option.如果我没有
updateEl
选项,我想知道这是否正确。
Thanks in advance for every support预先感谢您的每一次支持
Use a function that returns either updateEl
or createEl
as the field to order by.使用返回
updateEl
或createEl
作为排序依据的字段的 function。
orderBy(myData, el => el.updateEl || el.createEl)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.