【发布时间】:2021-07-17 13:21:25
【问题描述】:
我想根据 widgetOrder 数组中的 sort_number 对 widgets 数组进行排序和重新排列。 我尝试循环小部件数组以比较 widgetOrder 中的 sort_number。此小部件数组表示管理面板仪表板页面上的项目。它具有称为小部件的磁贴,可以更改其位置或显示顺序。当一个瓦片的位置改变时,它被推送到widgetOrder。!
const widgets =
[
{
id: 59,
roleId: 3,
widgetId: 1,
sort_number: 1,
created_by: '1',
updated_by: '1',
createdAt: '2021 - 04 - 22T03: 09: 32.098Z',
updatedAt: '2021 - 04 - 22T03: 09: 32.098Z',
'dashboardWidget.id': 1,
'dashboardWidget.name': 'bookingCount',
'dashboardWidget.displayName': 'Booking Count',
'dashboardWidget.description': 'Shows the count of total bookings for the time period if specified, otherwise shows all booking count',
'dashboardWidget.isCounter': 1
},
{
id: 60,
roleId: 3,
widgetId: 2,
sort_number: 2,
created_by: '1',
updated_by: '1',
createdAt: '2021 - 04 - 22T03: 09: 32.098Z',
updatedAt: '2021 - 04 - 22T03: 09: 32.098Z',
'dashboardWidget.id': 2,
'dashboardWidget.name': 'pickUpCount',
'dashboardWidget.displayName': 'Pick-up Count',
'dashboardWidget.description': 'Shows the count of total pick-ups for the time period if specified, otherwise shows all pick-up count',
'dashboardWidget.isCounter': 1
},
{
id: 61,
roleId: 3,
widgetId: 3,
sort_number: 3,
created_by: '1',
updated_by: '1',
createdAt: '2021 - 04 - 22T03: 09: 32.098Z',
updatedAt: '2021 - 04 - 22T03: 09: 32.098Z',
'dashboardWidget.id': 3,
'dashboardWidget.name': 'dropOutCount',
'dashboardWidget.displayName': 'Drop-out Count',
'dashboardWidget.description': 'Shows the count of total drop-outs for the time period if specified, otherwise shows all drop-out count',
'dashboardWidget.isCounter': 1
},
{
id: 62,
roleId: 3,
widgetId: 9,
sort_number: 4,
created_by: '1',
updated_by: '1',
createdAt: '2021 - 04 - 22T03: 09: 32.098Z',
updatedAt: '2021 - 04 - 22T03: 09: 32.098Z',
'dashboardWidget.id': 9,
'dashboardWidget.name': 'enquiryCount',
'dashboardWidget.displayName': 'Enquiry Count',
'dashboardWidget.description': 'Shows the count of total enquires for the time period if specified, otherwise shows all enquiry count',
'dashboardWidget.isCounter': 1
}
];
const widgetOrder = [
{ widgetId: 2, sort_number: 4, is_visible: 1 },
{ widgetId: 3, sort_number: 1, is_visible: 1 }
];
【问题讨论】:
-
您的最终预期结果是什么?
-
元素没有排序怎么办,
标签: javascript node.js arrays angular typescript