jquery own sorting method (js also)

jquery.sort()
 
js.sort()
<!DOCTYPE html>
<html>
   <head>
     <meta charset= "UTF-8" >
     <title></title>
     <script src= "http://libs.baidu.com/jquery/2.0.0/jquery.min.js" ></script>
   </head>
   <body>
     <script type= "text/javascript" >
       //利用jquery中的get方法获取json数据
       $.get( "exp.json" , "" , function (data){
         var newdata=data.result
         //根据价格(price)排序
         function sortprice(a,b){
           return a.price-b.price
         }
         //利用js中的sort方法
         newdata.sort(sortprice);
         //打印排序后的数据到控制台
         console.log(newdata);
       })
     </script>
   </body>
</html>

Guess you like

Origin www.cnblogs.com/mark5/p/11593590.html