判断list中的对象的某个字段是否是连续的

版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
本文链接:https://blog.csdn.net/Silence_Sep/article/details/84950888

var hint = ‘’
params.scheduleList = _.sortBy(params.scheduleList, ‘routeNo’);
var b = [];
var lastRoutNo = params.scheduleListAll.length

					var hasLastNo = false;
					params.scheduleList.forEach(n => {
						b.push(n)
						if(n.routeNo == lastRoutNo) {
							hasLastNo = true;
						}
					})
					var reverseList = _.reverse(b)
					var count = 0;
					for(var i = 0; i < params.scheduleList.length - 1; i++) {
						if(reverseList[i].routeNo - params.scheduleList[params.scheduleList.length - i - 2].routeNo == 1) {
							count++
						}
					}
					if(count != params.scheduleList.length - 1) {
						this.$message({
							message: '请选择连续的航段',
							type: 'warning'
						})
						return
					}
					if(!hasLastNo) {
						this.$message({
							message: '请选择最后一个航段',
							type: 'warning'
						})
						return
					}

					params.scheduleList.forEach(n => {
						hint += n.routeNo + ","
					})

					if(hint.endsWith(",")) {
						hint = hint.substring(0, hint.length - 1);
					}
展开阅读全文

没有更多推荐了,返回首页