javascript-AngularJs对象排序
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了javascript-AngularJs对象排序,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含3193字,纯文字阅读大概需要5分钟。
内容图文
我在主数组对象中有这样的JSON
obj = [{{"title":"1-Introduction"},
{"title":"5-Introduction"},
{"title":"20-Introduction"},
{"title":"4-Introduction"} }]
我想对上述对象进行排序
obj = [{{"title":"1-Introduction"},
{"title":"4-Introduction"},
{"title":"5-Introduction"},
{"title":"20-Introduction"} }]
到目前为止我尝试过的
$scope.checkWeightage=function(){
thisObj.scheduleSubject.map(itm=>itm.sectionRange.map(subItm=>{
var min = subItm.chapterActualWeightage-(subItm.chapterActualWeightage/10);
var max = subItm.chapterActualWeightage+(subItm.chapterActualWeightage/10);
var sum = subItm.items.reduce((total,it)=>{
return total+it.actualWeightage;
},0);
subItm['weightageError'] = (sum>max || sum<min)?true:false;
subItm['ChapterActualWeightageCurrently'] = parseFloat(Math.round(sum*100)/100);
subItm.items.sort((a,b)=>a.title.split(/_(.+)/)[0]>b.title.split(/_(.+)/)[0]);
})
); console.log(thisObj.scheduleSubject[0].chapterData); //.1[0].title);
//console.log("CHECK weightage",thisObj.scheduleSubject);
}
如何在我的主阵列上跟踪标题
alert(thisObj.scheduleSubject[0].sectionRange[0].items[0].title);
我想在其标题数字的基础上对所有项目进行排序-字符示例1-,2-,3-,4-,5-,6-,21-,56-等.
主阵列结构
[
{
"id": "25",
"section": "1",
"sectionRange": [
{
"sectionNumber": 1,
"effectAllowed": "all",
"Date": "",
"items": [
{
"subjectId": 25,
"section": 1,
"chapterId": 283,
"actualWeightage": 3.42,
"totalPaperMarks": 132,
"title": "10-Creation & Registration of Charges",
"$$hashKey": "object:146"
},
{
"subjectId": 25,
"section": 1,
"chapterId": 284,
"actualWeightage": 2.23,
"totalPaperMarks": 132,
"title": "11-Allotment of Securities & Issue of Certificates",
"$$hashKey": "object:147"
},
{
"subjectId": 25,
"section": 1,
"chapterId": 285,
"actualWeightage": 1.37,
"totalPaperMarks": 132,
"title": "12-Membership in a Company",
"$$hashKey": "object:148"
},
{
"subjectId": 25,
"section": 1,
"chapterId": 286,
"actualWeightage": 3.42,
"totalPaperMarks": 132,
"title": "13-Transfer & Transmission of Securities",
"$$hashKey": "object:149"
},
{
"subjectId": 25,
"section": 1,
"chapterId": 287,
"actualWeightage": 7.53,
"totalPaperMarks": 132,
"title": "14-Institution of Directors",
"$$hashKey": "object:150"
},
{
"subjectId": 25,
"section": 1,
"chapterId": 288,
"actualWeightage": 1.37,
"totalPaperMarks": 132,
"title": "15-Independent Directors",
"$$hashKey": "object:151"
},
{
"subjectId": 25,
"section": 1,
"chapterId": 289,
"actualWeightage": 13.35,
"totalPaperMarks": 132,
"title": "16-Board & its Powers",
"$$hashKey": "object:152"
},
{
"subjectId": 25,
"section": 1,
"chapterId": 290,
"actualWeightage": 8.22,
"totalPaperMarks": 132,
"title": "17-Appointment & Remuneration of Key Managerial Personnel",
"$$hashKey": "object:153"
},
{
"subjectId": 25,
"section": 1,
"chapterId": 291,
"actualWeightage": 6.68,
"totalPaperMarks": 132,
"title": "18-General Meetings",
"$$hashKey": "object:154"
},
{
"subjectId": 25,
"section": 1,
"chapterId": 292,
"actualWeightage": 1.37,
"totalPaperMarks": 132,
"title": "19-Loans & Investments by Companies",
"$$hashKey": "object:155"
}
解决方法:
您可以拆分该char并通过它进行排序(假设您的主要数据结构被命名为structure:
structure.forEach(s => {
s.sectionRange.forEach(sr => {
sr.items.sort(function(a, b) {
let aParts = a.split("-"),
bParts = b.split("-");
return +aParts[0] - +bParts[0];
});
});
});
内容总结
以上是互联网集市为您收集整理的javascript-AngularJs对象排序全部内容,希望文章能够帮你解决javascript-AngularJs对象排序所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。