Mat*_*zia 0 javascript sorting algorithm methods reactjs
你好,我正在尝试对这个关注数据进行排序
[
{
"clockId": 27,
"clockResetId": 2,
"clockName": " clock1",
"station": "Byron",
"department": "",
"owner": "",
"type": "Discretionary",
"fleetClockGlobalRecordDays": null,
"clockLevel": "Fleet",
"clockDescription": "",
"eventDate": "2020-05-02Z",
"totalDays": 18,
"irNum": "123",
"observationNum": "",
"toolToPrevent": "123",
"eventDescription": "123",
"clockSetter": "sarahevelynn",
"resetHistory": [
{
"yearSubFour": 0,
"yearSubThree": 0,
"yearSubTwo": 0,
"yearSubOne": 0,
"maxTotalDays": 0,
"year": 1,
"clockId": 27
}
],
"backgroundColor": "#fe001c",
"textColor": "#ffffff"
},
{
"clockId": 46,
"clockResetId": 2,
"clockName": "clock undenfiend",
"station": "Dresden",
"department": "",
"owner": "",
"type": "",
"fleetClockGlobalRecordDays": null,
"clockLevel": "Fleet",
"clockDescription": "",
"eventDate": "2020-05-02Z",
"totalDays": 20,
"irNum": "123",
"observationNum": "",
"toolToPrevent": "123",
"eventDescription": "123",
"clockSetter": "sarahevelynn",
"resetHistory": [
{
"yearSubFour": 0,
"yearSubThree": 0,
"yearSubTwo": 0,
"yearSubOne": 0,
"maxTotalDays": 0,
"year": 1,
"clockId": 27
}
],
"backgroundColor": "#fe001c",
"textColor": "#ffffff"
},
{
"clockId": 13,
"clockResetId": 1,
"clockName": " clock ",
"station": "Byron",
"department": "",
"owner": "",
"type": "Non-Discretionary",
"fleetClockGlobalRecordDays": null,
"clockLevel": "Fleet",
"clockDescription": "testing ",
"eventDate": "2020-04-28Z",
"totalDays": 22,
"irNum": "123",
"observationNum": "",
"toolToPrevent": "tool",
"eventDescription": "testing ",
"clockSetter": "sarahevelynn",
"resetHistory": [
{
"yearSubFour": 0,
"yearSubThree": 0,
"yearSubTwo": 0,
"yearSubOne": 0,
"maxTotalDays": 0,
"year": 1,
"clockId": 13
}
],
"backgroundColor": "#fe001c",
"textColor": "#ffffff"
},
{
"clockId": 43,
"clockResetId": 2,
"clockName": " clock1",
"station": "Braidwood",
"department": "",
"owner": "",
"type": "Discretionary",
"fleetClockGlobalRecordDays": null,
"clockLevel": "Fleet",
"clockDescription": "",
"eventDate": "2020-05-02Z",
"totalDays": 23,
"irNum": "123",
"observationNum": "",
"toolToPrevent": "123",
"eventDescription": "123",
"clockSetter": "sarahevelynn",
"resetHistory": [
{
"yearSubFour": 0,
"yearSubThree": 0,
"yearSubTwo": 0,
"yearSubOne": 0,
"maxTotalDays": 0,
"year": 1,
"clockId": 27
}
],
"backgroundColor": "#fe001c",
"textColor": "#ffffff"
},
{
"clockId": 42,
"clockResetId": 2,
"clockName": " clock1",
"station": "Clinton",
"department": "",
"owner": "",
"type": "Discretionary",
"fleetClockGlobalRecordDays": null,
"clockLevel": "Fleet",
"clockDescription": "",
"eventDate": "2020-05-02Z",
"totalDays": 28,
"irNum": "123",
"observationNum": "",
"toolToPrevent": "123",
"eventDescription": "123",
"clockSetter": "sarahevelynn",
"resetHistory": [
{
"yearSubFour": 0,
"yearSubThree": 0,
"yearSubTwo": 0,
"yearSubOne": 0,
"maxTotalDays": 0,
"year": 1,
"clockId": 27
}
],
"backgroundColor": "#f6ea00",
"textColor": "#000000"
},
{
"clockId": 49,
"clockResetId": 2,
"clockName": " clock undefiend",
"station": "Byron",
"department": "",
"owner": "",
"type": "",
"fleetClockGlobalRecordDays": null,
"clockLevel": "Fleet",
"clockDescription": "",
"eventDate": "2020-05-02Z",
"totalDays": 28,
"irNum": "123",
"observationNum": "",
"toolToPrevent": "123",
"eventDescription": "123",
"clockSetter": "sarahevelynn",
"resetHistory": [
{
"yearSubFour": 0,
"yearSubThree": 0,
"yearSubTwo": 0,
"yearSubOne": 0,
"maxTotalDays": 0,
"year": 1,
"clockId": 27
}
],
"backgroundColor": "#f6ea00",
"textColor": "#000000"
},
{
"clockId": 41,
"clockResetId": 4,
"clockName": "clearance and tagging",
"station": "Byron",
"department": "",
"owner": "",
"type": "Non-Discretionary",
"fleetClockGlobalRecordDays": null,
"clockLevel": "Fleet",
"clockDescription": "",
"eventDate": "2020-04-18Z",
"totalDays": 32,
"irNum": "123",
"observationNum": "",
"toolToPrevent": "123",
"eventDescription": "123",
"clockSetter": "sarahevelynn",
"resetHistory": [
{
"yearSubFour": 0,
"yearSubThree": 0,
"yearSubTwo": 0,
"yearSubOne": 0,
"maxTotalDays": 0,
"year": 1,
"clockId": 41
}
],
"backgroundColor": "#f6ea00",
"textColor": "#000000"
},
{
"clockId": 41,
"clockResetId": 4,
"clockName": "clearance and tagging",
"station": "Byron",
"department": "",
"owner": "",
"type": "Non-Discretionary",
"fleetClockGlobalRecordDays": null,
"clockLevel": "Fleet",
"clockDescription": "",
"eventDate": "2020-04-18Z",
"totalDays": 32,
"irNum": "123",
"observationNum": "",
"toolToPrevent": "123",
"eventDescription": "123",
"clockSetter": "sarahevelynn",
"resetHistory": [
{
"yearSubFour": 0,
"yearSubThree": 0,
"yearSubTwo": 0,
"yearSubOne": 0,
"maxTotalDays": 0,
"year": 1,
"clockId": 41
}
],
"backgroundColor": "#f6ea00",
"textColor": "#000000"
},
{
"clockId": 41,
"clockResetId": 4,
"clockName": "clearance and tagging",
"station": "Byron",
"department": "",
"owner": "",
"type": "Non-Discretionary",
"fleetClockGlobalRecordDays": null,
"clockLevel": "Fleet",
"clockDescription": "",
"eventDate": "2020-04-18Z",
"totalDays": 32,
"irNum": "123",
"observationNum": "",
"toolToPrevent": "123",
"eventDescription": "123",
"clockSetter": "sarahevelynn",
"resetHistory": [
{
"yearSubFour": 0,
"yearSubThree": 0,
"yearSubTwo": 0,
"yearSubOne": 0,
"maxTotalDays": 0,
"year": 1,
"clockId": 41
}
],
"backgroundColor": "#f6ea00",
"textColor": "#000000"
},
{
"clockId": 41,
"clockResetId": 4,
"clockName": "clearance and tagging",
"station": "Byron",
"department": "",
"owner": "",
"type": "Non-Discretionary",
"fleetClockGlobalRecordDays": null,
"clockLevel": "Fleet",
"clockDescription": "",
"eventDate": "2020-04-18Z",
"totalDays": 32,
"irNum": "123",
"observationNum": "",
"toolToPrevent": "123",
"eventDescription": "123",
"clockSetter": "sarahevelynn",
"resetHistory": [
{
"yearSubFour": 0,
"yearSubThree": 0,
"yearSubTwo": 0,
"yearSubOne": 0,
"maxTotalDays": 0,
"year": 1,
"clockId": 41
}
],
"backgroundColor": "#f6ea00",
"textColor": "#000000"
},
{
"clockId": 41,
"clockResetId": 4,
"clockName": "clearance and tagging",
"station": "Byron",
"department": "",
"owner": "",
"type": "Non-Discretionary",
"fleetClockGlobalRecordDays": null,
"clockLevel": "Fleet",
"clockDescription": "",
"eventDate": "2020-04-18Z",
"totalDays": 32,
"irNum": "123",
"observationNum": "",
"toolToPrevent": "123",
"eventDescription": "123",
"clockSetter": "sarahevelynn",
"resetHistory": [
{
"yearSubFour": 0,
"yearSubThree": 0,
"yearSubTwo": 0,
"yearSubOne": 0,
"maxTotalDays": 0,
"year": 1,
"clockId": 41
}
],
"backgroundColor": "#f6ea00",
"textColor": "#000000"
},
{
"clockId": 41,
"clockResetId": 4,
"clockName": "clearance and tagging",
"station": "Byron",
"department": "",
"owner": "",
"type": "Non-Discretionary",
"fleetClockGlobalRecordDays": null,
"clockLevel": "Fleet",
"clockDescription": "",
"eventDate": "2020-04-18Z",
"totalDays": 32,
"irNum": "123",
"observationNum": "",
"toolToPrevent": "123",
"eventDescription": "123",
"clockSetter": "sarahevelynn",
"resetHistory": [
{
"yearSubFour": 0,
"yearSubThree": 0,
"yearSubTwo": 0,
"yearSubOne": 0,
"maxTotalDays": 0,
"year": 1,
"clockId": 41
}
],
"backgroundColor": "#f6ea00",
"textColor": "#000000"
},
{
"clockId": 41,
"clockResetId": 4,
"clockName": "clearance and tagging",
"station": "Byron",
"department": "",
"owner": "",
"type": "Non-Discretionary",
"fleetClockGlobalRecordDays": null,
"clockLevel": "Fleet",
"clockDescription": "",
"eventDate": "2020-04-18Z",
"totalDays": 32,
"irNum": "123",
"observationNum": "",
"toolToPrevent": "123",
"eventDescription": "123",
"clockSetter": "sarahevelynn",
"resetHistory": [
{
"yearSubFour": 0,
"yearSubThree": 0,
"yearSubTwo": 0,
"yearSubOne": 0,
"maxTotalDays": 0,
"year": 1,
"clockId": 41
}
],
"backgroundColor": "#f6ea00",
"textColor": "#000000"
},
{
"clockId": 41,
"clockResetId": 4,
"clockName": "clearance and tagging",
"station": "Byron",
"department": "",
"owner": "",
"type": "Non-Discretionary",
"fleetClockGlobalRecordDays": null,
"clockLevel": "Fleet",
"clockDescription": "",
"eventDate": "2020-04-18Z",
"totalDays": 32,
"irNum": "123",
"observationNum": "",
"toolToPrevent": "123",
"eventDescription": "123",
"clockSetter": "sarahevelynn",
"resetHistory": [
{
"yearSubFour": 0,
"yearSubThree": 0,
"yearSubTwo": 0,
"yearSubOne": 0,
"maxTotalDays": 0,
"year": 1,
"clockId": 41
}
],
"backgroundColor": "#f6ea00",
"textColor": "#000000"
},
{
"clockId": 41,
"clockResetId": 4,
"clockName": "clearance and tagging",
"station": "Byron",
"department": "",
"owner": "",
"type": "Non-Discretionary",
"fleetClockGlobalRecordDays": null,
"clockLevel": "Fleet",
"clockDescription": "",
"eventDate": "2020-04-18Z",
"totalDays": 32,
"irNum": "123",
"observationNum": "",
"toolToPrevent": "123",
"eventDescription": "123",
"clockSetter": "sarahevelynn",
"resetHistory": [
{
"yearSubFour": 0,
"yearSubThree": 0,
"yearSubTwo": 0,
"yearSubOne": 0,
"maxTotalDays": 0,
"year": 1,
"clockId": 41
}
],
"backgroundColor": "#f6ea00",
"textColor": "#000000"
},
{
"clockId": 41,
"clockResetId": 4,
"clockName": "clearance and tagging",
"station": "Byron",
"department": "",
"owner": "",
"type": "Non-Discretionary",
"fleetClockGlobalRecordDays": null,
"clockLevel": "Fleet",
"clockDescription": "",
"eventDate": "2020-04-18Z",
"totalDays": 32,
"irNum": "123",
"observationNum": "",
"toolToPrevent": "123",
"eventDescription": "123",
"clockSetter": "sarahevelynn",
"resetHistory": [
{
"yearSubFour": 0,
"yearSubThree": 0,
"yearSubTwo": 0,
"yearSubOne": 0,
"maxTotalDays": 0,
"year": 1,
"clockId": 41
}
],
"backgroundColor": "#f6ea00",
"textColor": "#000000"
},
{
"clockId": 41,
"clockResetId": 4,
"clockName": "clearance and tagging",
"station": "Byron",
"department": "",
"owner": "",
"type": "Non-Discretionary",
"fleetClockGlobalRecordDays": null,
"clockLevel": "Fleet",
"clockDescription": "",
"eventDate": "2020-04-18Z",
"totalDays": 32,
"irNum": "123",
"observationNum": "",
"toolToPrevent": "123",
"eventDescription": "123",
"clockSetter": "sarahevelynn",
"resetHistory": [
{
"yearSubFour": 0,
"yearSubThree": 0,
"yearSubTwo": 0,
"yearSubOne": 0,
"maxTotalDays": 0,
"year": 1,
"clockId": 41
}
],
"backgroundColor": "#f6ea00",
"textColor": "#000000"
},
{
"clockId": 41,
"clockResetId": 4,
"clockName": "clearance and tagging",
"station": "Byron",
"department": "",
"owner": "",
"type": "Non-Discretionary",
"fleetClockGlobalRecordDays": null,
"clockLevel": "Fleet",
"clockDescription": "",
"eventDate": "2020-04-18Z",
"totalDays": 32,
"irNum": "123",
"observationNum": "",
"toolToPrevent": "123",
"eventDescription": "123",
"clockSetter": "sarahevelynn",
"resetHistory": [
{
"yearSubFour": 0,
"yearSubThree": 0,
"yearSubTwo": 0,
"yearSubOne": 0,
"maxTotalDays": 0,
"year": 1,
"clockId": 41
}
],
"backgroundColor": "#f6ea00",
"textColor": "#000000"
},
{
"clockId": 44,
"clockResetId": 2,
"clockName": " clock1",
"station": "Dresden",
"department": "",
"owner": "",
"type": "Discretionary",
"fleetClockGlobalRecordDays": null,
"clockLevel": "Fleet",
"clockDescription": "",
"eventDate": "2020-05-02Z",
"totalDays": 38,
"irNum": "123",
"observationNum": "",
"toolToPrevent": "123",
"eventDescription": "123",
"clockSetter": "sarahevelynn",
"resetHistory": [
{
"yearSubFour": 0,
"yearSubThree": 0,
"yearSubTwo": 0,
"yearSubOne": 0,
"maxTotalDays": 0,
"year": 1,
"clockId": 27
}
],
"backgroundColor": "#f6ea00",
"textColor": "#000000"
},
{
"clockId": 47,
"clockResetId": 2,
"clockName": " clock undenfiend",
"station": "Byron",
"department": "",
"owner": "",
"type": "",
"fleetClockGlobalRecordDays": null,
"clockLevel": "Fleet",
"clockDescription": "",
"eventDate": "2020-05-02Z",
"totalDays": 38,
"irNum": "123",
"observationNum": "",
"toolToPrevent": "123",
"eventDescription": "123",
"clockSetter": "sarahevelynn",
"resetHistory": [
{
"yearSubFour": 0,
"yearSubThree": 0,
"yearSubTwo": 0,
"yearSubOne": 0,
"maxTotalDays": 0,
"year": 1,
"clockId": 27
}
],
"backgroundColor": "#f6ea00",
"textColor": "#000000"
},
{
"clockId": 55,
"clockResetId": 3,
"clockName": "configuration control",
"station": "Byron",
"department": "",
"owner": "",
"type": "Non-Discretionary",
"fleetClockGlobalRecordDays": null,
"clockLevel": "Fleet",
"clockDescription": "",
"eventDate": "2020-04-01Z",
"totalDays": 149,
"irNum": "123",
"observationNum": "",
"toolToPrevent": "123",
"eventDescription": "123",
"clockSetter": "sarahevelynn",
"resetHistory": [
{
"yearSubFour": 0,
"yearSubThree": 0,
"yearSubTwo": 0,
"yearSubOne": 0,
"maxTotalDays": 0,
"year": 1,
"clockId": 55
}
],
"backgroundColor": null,
"textColor": "#000000"
},
{
"clockId": 55,
"clockResetId": 3,
"clockName": "configuration control",
"station": "Byron",
"department": "",
"owner": "",
"type": "Non-Discretionary",
"fleetClockGlobalRecordDays": null,
"clockLevel": "Fleet",
"clockDescription": "",
"eventDate": "2020-04-01Z",
"totalDays": 149,
"irNum": "123",
"observationNum": "",
"toolToPrevent": "123",
"eventDescription": "123",
"clockSetter": "sarahevelynn",
"resetHistory": [
{
"yearSubFour": 0,
"yearSubThree": 0,
"yearSubTwo": 0,
"yearSubOne": 0,
"maxTotalDays": 0,
"year": 1,
"clockId": 55
}
],
"backgroundColor": null,
"textColor": "#000000"
},
{
"clockId": 55,
"clockResetId": 3,
"clockName"
由于station是字符串而不是数字,sort回调中的以下表达式将无法按预期工作:
a.station - b.station || a.totalDays - b.totalDays
Run Code Online (Sandbox Code Playgroud)
表达式的前半部分将评估为NaN,因此后半部分始终是总评估的决定因素。
您需要以“字符串”方式进行比较:
a.station.localeCompare(b.station) || a.totalDays - b.totalDays
Run Code Online (Sandbox Code Playgroud)