I'm having trouble sorting an object by TearSheetTypeName and StartDate using Javascript or Underscore.js. The object looks like this:
{
Components: {141: {TearSheetTypeName: "Skyscraper", StartDate: "2015-01-01"}}
{142: {TearSheetTypeName: "Skyscraper", StartDate: "2015-01-01"}}
{145: {TearSheetTypeName: "New Car", StartDate: "2015-01-15"}}
{146: {TearSheetTypeName: "New Car", StartDate: "2015-01-01"}}
}
The result I'd like:
{
Components: {146: {TearSheetTypeName: "New Car", StartDate: "2015-01-01"}}
{145: {TearSheetTypeName: "New Car", StartDate: "2015-01-15"}}
{141: {TearSheetTypeName: "Skyscraper", StartDate: "2015-01-01"}}
{142: {TearSheetTypeName: "Skyscraper", StartDate: "2015-01-01"}}
}
I tried doing this:
data = _.sortBy(data, function(obj) {
return obj.TearSheetTypeName;
});
But it changed the object to use 0, 1, 2, 3 as object names instead of 141, 142, 145, and 146. It also doesn't take the StartDate into consideration.
Any help would be appreciated. Thanks.