考卷生成的需求,尝试vue实现。
代码大致结构如下:
预设小题分值: 该题总分:{{bigtotal}}
增加一个小题按钮
设置该小题分值:
增加一个大题按钮
var vu = new Vue({
el: '#todo-list-example',
data: {
all:[],
onebig:{qtype:'',title:'xxx',bmark:0,questions:[]},//大题数据模板
onesmall:{smark:0,stem:'',answer1:'',answer2:'',answer3:'',answer4:''}//小题数据模板
},
methods: {
addbig: function() {//增加大题
let onebig_str = JSON.parse(JSON.stringify(this.onebig));
this.all.push(onebig_str);
//....
},
addsmall: function(index) {//增加小题
let onebig_str = JSON.parse(JSON.stringify(vu.onesmall));
this.all[index].questions.push(onebig_str);
//....
});
},
}
})
问题:预设小题分值的时候,则该大题内所有小题分值改变。修改某个小题的分值,该大题总分自动计算得到。
由于大题小题都是按钮点击push生成,两个for循环这里,我怎么算分数呢?
求实现思路