问题
_.sortBy(arrData, "rhid");
This code sorts array but as the values of field "rhid" are strings the order is messed up. How can i sort as if "rhid" where int field.
Thanks
回答1:
sortBy can be used with a function instead of a property name.
_.sortBy(arrData, function (obj) {
return parseInt(obj.rhid, 10);
});
来源:https://stackoverflow.com/questions/34724034/sort-array-of-numeric-strings-with-lodash