I haven’t used it for a hundred years, so I picked it up today sort() sort

Insert image description here

Briefly describe the requirements.
Originally, the front-end calls the back-end interface with its own sorting function. Generally, it is based on the time when the document is created, and the back-end will process it and return it to us.
But sometimes there are special restrictions that require the front-end to handle the sorting and display by itself.
As shown in the figure above,
both the list and the list extension rows must be sorted according to the sort size passed in when we add or edit.
The larger the sort number is, the higher it is, then we use the sort() sorting method in the array.

First of all, we can definitely get the interface return data. At this time, the data format is the form of objects contained in the array.
Then it’s OK if we deal with it directly
. Let’s give an example first.
let arr = [
{'name': '张三', age: 26},
{'name': '李思', age: 12},
{'name': '王五', age: 37},
{ 'name': 'Zhao Liu', age: 4}
];

arr.sort(function (a,b) {
return b.age - a.age
})

console.log(arr)

Insert image description here
Then the idea is correct, let’s just get the data and process it.

Insert image description here
Insert image description here
Insert image description here
Insert image description here

The above figure shows that the interface request query is normally returned according to the adding time, and after front-end processing, it is a list display style.

おすすめ

転載: blog.csdn.net/lzfengquan/article/details/130637956