lodash orderby with null and real values not ordering correctly

后端 未结 6 735

I have an Angular 2 typescript application that is using lodash for various things.

I have an array of objects that I am ordering using a property in the object...

6条回答
  •  鱼传尺愫
    2021-01-07 23:08

    mine looks like this. PropName and sort are both variables in my solution

    return _.orderBy( myarray, [
      ( data ) => {
        if ( data[propName] === null ) {
            data[propName] = "";
        }
        return data[propName].toLowerCase();
        }
     ], [sort] );
    

    I wanted tolowercase because otherwise the sorting is not correct if different casings

自定义标题
段落格式
字体
字号
代码语言
提交回复
热议问题