jquery利用sort方法对json数据排序

var jsonData = [{ModuleId: "cda2c478", EnCode: "work", FullName: "工务","Sort":2},{ModuleId: "8474a702", EnCode: "Setting", FullName: "设置", ,"Sort":1},{ModuleId: "76b37fcb", EnCode: "Emp", FullName: "成员",,"Sort":3}];
    
console.info("排序之前:" + jsonData);
    
jsonData.sort(function(a,b)
{
 return a.Sort - b.Sort;   
});    
console.info("排序之后:" + jsonData);

如果对FullName字段进行排序,只需要修改a.FullName-b.FullName即可。

posted @ 2020-05-08 08:43  James·wang  阅读(1491)  评论(0编辑  收藏  举报