这是一个单选题的跳转需求:
单选题可以设置跳转逻辑,有三种逻辑,分别是
默认不跳转,跳转到指定题目,跳转到最后一题(就是把当前题目当成最后一题)
实现难点:
- 有7种题型,但是有一种不属于题型(分隔符)的范畴,所以需要初始化的时候将分隔符字段不参与序号计算之内
- 考虑如何处理这三种状态
- 要考虑多个单选题的情况
- 我们编辑或者修改某一个单选题的选项的时候不影响其他单选题的跳转
具体实现:
//筛选列表
screenList(code,index){ // index为当前的索引
if(code === "-1"){ // 跳转到最后一题
this.copyData.subjectList.map((item,idx)=>{
if(idx > index) item.isShow = false
})
}else if (code == null){ // 不操作
let status = true
this.copyData.subjectList.map((item,idx)=>{
if(idx > index){
if(status) item.isShow = true
if(item.subjectType == 1 && item.answerId != null){
let mdCode = item.answerList.find(it => it.answerId == item.answerId).arg1
this.screenList(mdCode,idx)
status = false
}
}
})
}else { // 开启筛选
let targetIndex = this.copyData.subjectList.findIndex(item => (this.isEditStatus ? item.subjectNum : item.arg1) == code)
let status = true
this.copyData.subjectList.map((item,idx)=>{
if(idx > index){ // 操作当前索引下方的元素
if(idx >= targetIndex){
if(status) item.isShow = true
if(item.subjectType == 1 && item.answerId != null){
let mdCode = item.answerList.find(it => it.answerId == item.answerId).arg1
this.screenList(mdCode,idx)
status = false
}
}
if(idx < targetIndex) {
item.isShow = false
}
}
})
}
},