①Json数组准备
var menuData1=[
{"orderid":-10,"text":"主页","title":"个人网站主页","url":"Default.aspx?TeacherID=153","visible":true,"target":"_self"},
{"orderid":10,"text":"个人新闻","title":"个人新闻","url":"News.aspx?TeacherID=153","visible":true,"target":"_self"},
{"orderid":5,"text":"发表论文","title":"发表论文","url":"Paper.aspx?TeacherID=153","visible":true,"target":"_self"},
{"orderid":2,"text":"出版专著","title":"出版专著","url":"Monograph.aspx?TeacherID=153","visible":true,"target":"_self"},
{"orderid":7,"text":"参与项目","title":"参与项目","url":"Project.aspx?TeacherID=153","visible":true,"target":"_self"},
{"orderid":8,"text":"个人荣誉","title":"个人荣誉","url":"Prize.aspx?TeacherID=153","visible":true,"target":"_self"},
{"orderid":1,"text":"发明专利","title":"发明专利","url":"Patent.aspx?TeacherID=153","visible":true,"target":"_self"},
{"orderid":0,"text":"文件共享","title":"文件共享","url":"FileShare.aspx?TeacherID=153","visible":true,"target":"_self"}
];
②这时需要先将数组按orderid升序排序,注意,sort方法会改写原来的数组:
menuData1.sort(function(a, b) { return a.orderid > b.orderid ? 1 : -1;} );//升序
③经过排序后,结果为:
menuData1=[
{"orderid":-10,"text":"主页","title":"个人网站主页","url":"Default.aspx?TeacherID=153","visible":true,"target":"_self"},
{"orderid":0,"text":"文件共享","title":"文件共享","url":"FileShare.aspx?TeacherID=153","visible":true,"target":"_self"},
{"orderid":1,"text":"发明专利","title":"发明专利","url":"Patent.aspx?TeacherID=153","visible":true,"target":"_self"},
{"orderid":2,"text":"出版专著","title":"出版专著","url":"Monograph.aspx?TeacherID=153","visible":true,"target":"_self"},
{"orderid":5,"text":"发表论文","title":"发表论文","url":"Paper.aspx?TeacherID=153","visible":true,"target":"_self"},
{"orderid":7,"text":"参与项目","title":"参与项目","url":"Project.aspx?TeacherID=153","visible":true,"target":"_self"},
{"orderid":8,"text":"个人荣誉","title":"个人荣誉","url":"Prize.aspx?TeacherID=153","visible":true,"target":"_self"},
{"orderid":10,"text":"个人新闻","title":"个人新闻","url":"News.aspx?TeacherID=153","visible":true,"target":"_self"}
];