var data =[  
        {  
            "cid":1,  
            "name":"aaa",  
            "price":1000  
        },{  
            "cid":2,  
            "name":"bbb",  
            "price":150  
        },{  
            "cid":3,  
            "name":"ccc",  
            "price":200  
        },{  
            "cid":4,  
            "name":"ddd",  
            "price":1500  
        },{  
            "cid":5,  
            "name":"eee",  
            "price":1100  
        }  
    ] 

  function sortprice(a,b){  

    //a-b为升序,b-a为降序

     return a.price-b.price  

  }

  data.sort(sortprice);  

  //sore之后的data及为按某字段排序后的json

 

 

posted on 2018-05-02 17:15  程序员丁先生  阅读(845)  评论(0编辑  收藏  举报