Sorting Select Option in Javascript - Based on multiple values in same row

前端 未结 1 357
无人及你
无人及你 2021-01-21 15:04

I have created a list box like this, and created a title bar which helps to sort data:

ID                 Name
--------------------------------------------------         


        
相关标签:
1条回答
  • 2021-01-21 15:48

    You can use the custom array sort take a look at this How to sort select base on an id ?

    The idea here is just create a arrray and sort that based on its value and than dynamically create the option based on the sorted value.

    Custom sorting code

    source.sort(function (x, y) {
      if (isAsc) 
         return y.id - x.id;
      else 
        return x.id - y.id;
    });
    
    0 讨论(0)
提交回复
热议问题